Files
amb_wechatapp/application/admin/controller/order/Refund.php
T

75 lines
1.9 KiB
PHP

<?php
namespace app\admin\controller\order;
use app\common\controller\Backend;
use think\Db;
/**
* 退款
*
* @icon fa fa-circle-o
*/
class Refund extends Backend
{
/**
* Course模型对象
* @var \app\admin\model\order\Course
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\order\Order;
}
/**
* 同意退款
*/
public function refund()
{
$orderNo = input('order_no');
$refundForm = input('form/a');
$order = $this->model
->with(['log','user','item','item.detail'])
->where([
'order_no'=>$orderNo
])
->find();
$order->getRelation('user')->visible(\app\admin\model\User::$listShowField);
if (!$order) {
$this->error(__('No Results were found'));
}
$order = $order->toArray();
$order['log'] = array_reverse($order['log']);
Db::startTrans();
try{
foreach ($order['item'] as $key => $goods){
$goods['detail'] = json_decode($goods['snapshoot'],true);
if(!isset($refundForm[$goods['id']]['price'])){
$this->error('退款数据异常');
}
if($refundForm[$goods['id']]['price'] > bcsub($goods['real_price'] , $goods['refund_price'],2)){
$this->error('「'.$goods['item_name'].'」超出实际可退款金额');
}
\app\admin\model\order\Refund::startRefund($order,$goods,$refundForm[$goods['id']]['price'],"{$goods['item_name']}退款",$refundForm[$goods['id']]['save_equity']);
}
Db::commit();
}catch (\Exception $e){
Db::rollback();
$this->error('退款数据异常,'.$e->getMessage());
}
return $this->success('退款成功');
}
}