|
|
@@ -27,7 +27,7 @@ class Order extends Backend |
|
|
|
*/ |
|
|
|
protected $relationSearch = true; |
|
|
|
|
|
|
|
protected $noNeedLogin=["export","finish","doRefund","carry"]; |
|
|
|
protected $noNeedLogin=["export","finish","doRefund","carry","resetOrder"]; |
|
|
|
|
|
|
|
/** |
|
|
|
* Order模型对象 |
|
|
@@ -773,4 +773,54 @@ class Order extends Backend |
|
|
|
$this->view->assign('refund_fee', $refund_fee); |
|
|
|
return $this->view->fetch(); |
|
|
|
} |
|
|
|
|
|
|
|
public function resetOrder(){ |
|
|
|
$out_trade_no = $this->request->get("out_trade_no");; |
|
|
|
$prod_id = $this->request->get("prod_id");; |
|
|
|
$order = $this->model->where([ |
|
|
|
'out_trade_no' => $out_trade_no])->find(); |
|
|
|
if (!$order){ |
|
|
|
return "查询主订单失败"; |
|
|
|
} |
|
|
|
//库存回滚 |
|
|
|
$model=new OrderProduct(); |
|
|
|
$sborder =$model->where([ |
|
|
|
'order_id' => $order['id'], |
|
|
|
'product_id'=>$prod_id |
|
|
|
])->find(); |
|
|
|
if (!$sborder){ |
|
|
|
return "查询子订单失败"; |
|
|
|
} |
|
|
|
try { |
|
|
|
//退款金额 |
|
|
|
$refund_fee = $sborder->price*$sborder->number; |
|
|
|
//修改退款金额 |
|
|
|
$order->refund_fee = $refund_fee; |
|
|
|
$order->save(); |
|
|
|
//退款 |
|
|
|
$param = [ |
|
|
|
"order_id"=>$order['out_trade_no'], |
|
|
|
"total_fee"=>$order['total_price'], |
|
|
|
"refund_fee"=>$refund_fee, |
|
|
|
"memo"=>'订单退款', |
|
|
|
]; |
|
|
|
$result = PayService::cancel($param,$order["pay_type"]); |
|
|
|
if (!$result['flag']) { |
|
|
|
return "退款失败".$result['msg']; |
|
|
|
} |
|
|
|
//修改库存 |
|
|
|
$product = new \app\admin\model\unishop\Product(); |
|
|
|
$product->where(["id" => $prod_id])->setInc("stock", $sborder["number"]); |
|
|
|
$product->where(["id" => $prod_id])->setInc("real_sales", -$sborder["number"]); |
|
|
|
//删除表数据 |
|
|
|
$modelde=new OrderProduct(); |
|
|
|
$modelde->where([ |
|
|
|
'order_id' => $order['id'], |
|
|
|
'product_id'=>$prod_id |
|
|
|
])->delete(); |
|
|
|
return "完成"; |
|
|
|
} catch (Exception $e) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |