|
@@ -12,6 +12,9 @@
|
|
|
namespace App\Services\Common;
|
|
namespace App\Services\Common;
|
|
|
|
|
|
|
|
use App\Models\ActionLogModel;
|
|
use App\Models\ActionLogModel;
|
|
|
|
|
+use App\Models\GoodsModel;
|
|
|
|
|
+use App\Models\GoodsSkuModel;
|
|
|
|
|
+use App\Models\MemberCouponModel;
|
|
|
use App\Models\OrderCommissionModel;
|
|
use App\Models\OrderCommissionModel;
|
|
|
use App\Models\OrderGoodsModel;
|
|
use App\Models\OrderGoodsModel;
|
|
|
use App\Models\OrderModel;
|
|
use App\Models\OrderModel;
|
|
@@ -605,7 +608,7 @@ class OrderService extends BaseService
|
|
|
return ['code' => 1, 'msg' => '参数错误'];
|
|
return ['code' => 1, 'msg' => '参数错误'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $order = $this->model->find($id);
|
|
|
|
|
|
|
+ $order = $this->model->with(['orderGoods'])->find($id);
|
|
|
if (!$order) {
|
|
if (!$order) {
|
|
|
return ['code' => 1, 'msg' => '订单不存在'];
|
|
return ['code' => 1, 'msg' => '订单不存在'];
|
|
|
}
|
|
}
|
|
@@ -614,21 +617,15 @@ class OrderService extends BaseService
|
|
|
return ['code' => 1, 'msg' => '只有待付款订单可以取消'];
|
|
return ['code' => 1, 'msg' => '只有待付款订单可以取消'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $updateData = [
|
|
|
|
|
- 'mark' => 0, // 标记为删除
|
|
|
|
|
- 'update_time' => time()
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- $result = $this->model->where('id', $id)->update($updateData);
|
|
|
|
|
-
|
|
|
|
|
- if ($result) {
|
|
|
|
|
- ActionLogModel::setTitle("取消订单");
|
|
|
|
|
- ActionLogModel::record();
|
|
|
|
|
- RedisService::keyDel("caches:orders:*");
|
|
|
|
|
- return ['code' => 0, 'msg' => '订单已取消'];
|
|
|
|
|
|
|
+ // 订单商品处理
|
|
|
|
|
+ if(!\App\Services\Api\OrderService::make()->cancel($order->user_id, $id)){
|
|
|
|
|
+ return ['code' => 1, 'msg' => \App\Services\Api\OrderService::make()->getError()];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return ['code' => 1, 'msg' => '操作失败'];
|
|
|
|
|
|
|
+ ActionLogModel::setTitle("取消订单");
|
|
|
|
|
+ ActionLogModel::record();
|
|
|
|
|
+ RedisService::keyDel("caches:orders:*");
|
|
|
|
|
+ return ['code' => 0, 'msg' => '订单已取消'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -706,7 +703,7 @@ class OrderService extends BaseService
|
|
|
return ['code' => 1, 'msg' => '参数错误'];
|
|
return ['code' => 1, 'msg' => '参数错误'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $order = $this->model->find($id);
|
|
|
|
|
|
|
+ $order = $this->model->with(['orderGoods'])->find($id);
|
|
|
if (!$order) {
|
|
if (!$order) {
|
|
|
return ['code' => 1, 'msg' => '订单不存在'];
|
|
return ['code' => 1, 'msg' => '订单不存在'];
|
|
|
}
|
|
}
|
|
@@ -721,8 +718,36 @@ class OrderService extends BaseService
|
|
|
'update_time' => time()
|
|
'update_time' => time()
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $result = $this->model->where('id', $id)->update($updateData);
|
|
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $result = $this->model->where('id', $id)->update($updateData);
|
|
|
|
|
+
|
|
|
|
|
+ // 商品库存返还
|
|
|
|
|
+ if ($order->order_goods) {
|
|
|
|
|
+ foreach ($order->order_goods as $goods) {
|
|
|
|
|
+ $goodsId = isset($goods['goods_id']) ? $goods['goods_id'] : 0;
|
|
|
|
|
+ $num = isset($goods['num']) ? $goods['num'] : 0;
|
|
|
|
|
+ $skuId = isset($goods['sku_id']) ? $goods['sku_id'] : 0;
|
|
|
|
|
+ if ($goodsId) {
|
|
|
|
|
+ GoodsModel::where(['id' => $goodsId])->update(['stock' => DB::raw("stock + {$num}"), 'update_time' => time()]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($skuId) {
|
|
|
|
|
+ GoodsSkuModel::where(['id' => $skuId])->update(['stock' => DB::raw("stock + {$num}"), 'update_time' => time()]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 优惠券返还
|
|
|
|
|
+ if($order->coupon_id>0){
|
|
|
|
|
+ MemberCouponModel::where(['coupon_id'=>$order->coupon_id,'user_id'=>$order->user_id])->update(['status'=>1,'remark'=>'订单退款返还','update_time'=>time()]);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (\Exception $exception){
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return ['code' => 1, 'msg' => '操作失败:'.$exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ DB::commit();
|
|
|
if ($result) {
|
|
if ($result) {
|
|
|
ActionLogModel::setTitle("同意退款");
|
|
ActionLogModel::setTitle("同意退款");
|
|
|
ActionLogModel::record();
|
|
ActionLogModel::record();
|