|
@@ -849,15 +849,18 @@ class Orders extends Api{
|
|
|
$uid = $this->checkLogin();
|
|
|
// 接收参数
|
|
|
$id = request('id',0);
|
|
|
- $status = 4;
|
|
|
+ $status = 12;
|
|
|
// 获取产品和数量
|
|
|
$oldData = $Model->query()->where([['id','=',$id],['custom_uid','=',$uid]])->first(['id','order_score','status','custom_uid','insert_time','regiment_id']);
|
|
|
// 如果用户不存在
|
|
|
if( !$oldData ) return json_send(['code'=>'error','msg'=>'订单不存在']);
|
|
|
// 如果已经取消
|
|
|
- if( $oldData['status'] == 4 ) return json_send(['code'=>'error','msg'=>'订单已取消']);
|
|
|
+ if( $oldData['status'] == 12 ) return json_send(['code'=>'error','msg'=>'订单已取消']);
|
|
|
// 如果团不存在
|
|
|
if( !$oldData['regiment_id'] ) return json_send(['code'=>'error','msg'=>'拼团不存在']);
|
|
|
+ //查询团信息
|
|
|
+ $regimentInfo = Regiment::query()->find($oldData['regiment_id']);
|
|
|
+ if( !$regimentInfo ) return json_send(['code'=>'error','msg'=>'拼团不存在']);
|
|
|
// 组合数据,写入订单表,子表
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
@@ -870,13 +873,32 @@ class Orders extends Api{
|
|
|
// 提示信息
|
|
|
return json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
|
|
|
}
|
|
|
- //取消加入团
|
|
|
- $regimentRes = Regiment::query()->where('id','=',$oldData['regiment_id'])->decrement('people_number',1);
|
|
|
- if( !$regimentRes ) {
|
|
|
- // 回退数据
|
|
|
- DB::rollBack();
|
|
|
- // 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
+ //开团用户取消团订单
|
|
|
+ if ($regimentInfo['people_number'] > 1 && $regimentInfo['custom_uid'] == $uid){
|
|
|
+ //查询团记录
|
|
|
+ $regimentRecordInfo = RegimentRecord::query()->where([['order_id','<>',$oldData['id']],['regiment_id','=',$regimentInfo['id']],['status','=',0]])->first();
|
|
|
+ if ($regimentRecordInfo){
|
|
|
+ //将参团成员中的第一个用户变成开团人
|
|
|
+ $result = Regiment::query()->where('id','=',$regimentRecordInfo['regiment_id'])->update(['custom_uid'=>$regimentRecordInfo['custom_uid']]);
|
|
|
+ if (!$result) {
|
|
|
+ DB::rollBack();
|
|
|
+ return json_send(['code'=>'error','msg'=>'取消拼团,改变开团人失败']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //扣减加入团人数
|
|
|
+ $regimentRes = Regiment::query()->where('id','=',$oldData['regiment_id'])->decrement('people_number',1);
|
|
|
+ if( !$regimentRes ) {
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 提示信息
|
|
|
+ return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $regimentRes = Regiment::query()->where('id','=',$oldData['regiment_id'])->update(['status'=>1]);
|
|
|
+ if (!$regimentRes){
|
|
|
+ DB::rollBack();
|
|
|
+ return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
+ }
|
|
|
}
|
|
|
//修改拼团记录
|
|
|
$regimentRes = RegimentRecord::query()->where([['order_id','=',$oldData['id'],]])->update(['status'=>'1']);
|