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('退款成功'); } }