|
@@ -223,6 +223,8 @@ class Orders extends Auth{
|
|
|
return json_send(['code'=>'error','msg'=>'取消关联订单失败','data'=>['error'=>$result['error']]]);
|
|
|
}
|
|
|
}
|
|
|
+ // 记录行为
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
|
|
|
// 提交数据
|
|
|
DB::commit();
|
|
|
// 告知结果
|
|
@@ -239,27 +241,64 @@ class Orders extends Auth{
|
|
|
* 退款
|
|
|
*
|
|
|
* */
|
|
|
- public function refund( Request $request, Model $Model,OrdersProduct $OrdersProduct,CustomScore $CustomScore,Payment $Payment){
|
|
|
+ public function refund( Request $request, Model $Model,OrdersProduct $OrdersProduct,Payment $Payment){
|
|
|
// 验证参数
|
|
|
$request->scene('refund')->validate();
|
|
|
// 接收参数
|
|
|
- $id = request('id',0);
|
|
|
- $orderInfo = $Model->query()->find($id);
|
|
|
- if (!$orderInfo) return json_send(['code'=>'error','msg'=>'订单不存在']);
|
|
|
- $params['out_trade_no'] = (string)$orderInfo['snowflake_id'];
|
|
|
- $Snowflake = new Snowflake();
|
|
|
- $out_refund_no = $Snowflake->next();
|
|
|
- $params['out_refund_no'] = (string)$out_refund_no;
|
|
|
- $params['refund'] = $orderInfo['pay_total'];
|
|
|
- $params['total'] = $orderInfo['pay_total'];
|
|
|
- $params['reason'] = '用户退款';
|
|
|
- $res = $Payment->refund($params);
|
|
|
- if (!$res) return json_send(['code'=>'error','msg'=>'退款失败']);
|
|
|
- //修改订单状态
|
|
|
- $res = $Model->query()->where('snowflake_id','=',$orderInfo['snowflake_id'])->update(['out_refund_no'=>$out_refund_no,'status'=>5]);
|
|
|
- //修改订单产品状态
|
|
|
- $res = $OrdersProduct->query()->where('order_id','=',$id)->update(['status'=>5]);
|
|
|
- return json_send(['code'=>'success','msg'=>'退款成功']);
|
|
|
+ $id = request('id',0);
|
|
|
+ // 查询数据
|
|
|
+ $orderInfo = $Model->query()->find($id);
|
|
|
+ // 数据信息
|
|
|
+ if (!$orderInfo) return json_send(['code'=>'error','msg'=>'订单不存在']);
|
|
|
+ // 订单编号
|
|
|
+ $params['out_trade_no'] = (string)$orderInfo['snowflake_id'];
|
|
|
+ $out_refund_no = (new Snowflake())->next();
|
|
|
+ $params['out_refund_no'] = (string)$out_refund_no;
|
|
|
+ // 组合数据,写入订单表,子表
|
|
|
+ DB::beginTransaction();
|
|
|
+ // 尝试
|
|
|
+ try {
|
|
|
+ //修改订单状态
|
|
|
+ $res = $Model->query()->where('snowflake_id','=',$orderInfo['snowflake_id'])->update(['out_refund_no'=>$out_refund_no,'status'=>5]);
|
|
|
+ // 错误提醒
|
|
|
+ if (!$res) {
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 返回结果
|
|
|
+ return json_send(['code'=>'error','msg'=>'退款失败']);
|
|
|
+ }
|
|
|
+ //修改订单产品状态
|
|
|
+ $res = $OrdersProduct->query()->where('order_id','=',$id)->update(['status'=>5]);
|
|
|
+ // 错误提醒
|
|
|
+ if (!$res) {
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 返回结果
|
|
|
+ return json_send(['code'=>'error','msg'=>'退款失败']);
|
|
|
+ }
|
|
|
+ // 组合参数
|
|
|
+ $params['refund'] = $orderInfo['pay_total'];
|
|
|
+ $params['total'] = $orderInfo['pay_total'];
|
|
|
+ $params['reason'] = '用户退款';
|
|
|
+ $res = $Payment->refund($params);
|
|
|
+ if (!$res) {
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 返回结果
|
|
|
+ return json_send(['code'=>'error','msg'=>'退款失败']);
|
|
|
+ }
|
|
|
+ // 记录行为
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$orderInfo,['status'=>5]);
|
|
|
+ // 提交数据
|
|
|
+ DB::commit();
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code'=>'success','msg'=>'退款成功','path'=>'']);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 下单失败提示
|
|
|
+ return json_send(['code'=>'error','msg'=>'退款失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* 表格导入
|