Sfoglia il codice sorgente

【Mod】修改拼团缺陷

liuxiangxin 1 mese fa
parent
commit
ad5c83c026

+ 8 - 8
app/Http/Controllers/Admin/RegimentRecord.php

@@ -65,7 +65,7 @@ class RegimentRecord extends Auth{
 		// 数据类型
 		$shopIds				= ($session['menu_type'] == 1 && $session['data_type'] == 2)  ? Business::query()->where('leader_uid',$session['admin_uid'])->pluck('id')->toArray() : [];
 		
-        $select = [
+        $select                 = [
             'regiment_record.*',
             'regiment.status as regiment_status',
             'regiment.custom_uid as regiment_uid',
@@ -75,17 +75,17 @@ class RegimentRecord extends Auth{
         ];
         // 查询数据
         $list					= $Model->query()
-            ->join('regiment','regiment.id','=','regiment_record.regiment_id')
-            ->join('regiment_active','regiment_active.id','=','regiment_record.active_id')
-            ->join('product','product.id','=','regiment_record.product_id')
-            ->join('custom','custom.uid','=','regiment_record.custom_uid');
+                                    ->join('regiment','regiment.id','=','regiment_record.regiment_id')
+                                    ->join('regiment_active','regiment_active.id','=','regiment_record.active_id')
+                                    ->join('product','product.id','=','regiment_record.product_id')
+                                    ->join('custom','custom.uid','=','regiment_record.custom_uid');
         if ($shopIds){
             $list               = $list->whereIn('regiment_active.business_id',$shopIds);
         }
         $list					= $list->where($map)
-            ->select($select)
-            ->orderByDesc('id')
-            ->paginate(config('page_num',10))->appends(request()->all());
+                                    ->select($select)
+                                    ->orderByDesc('id')
+                                    ->paginate(config('page_num',10))->appends(request()->all());
         // 循环处理数据
         foreach($list as &$v){
             $v['product_code']          = $Product->idToCode($v['product_id']);

+ 49 - 34
app/Http/Controllers/Api/Orders.php

@@ -651,9 +651,7 @@ class Orders extends Api{
         // 检查登录
         $uid							= $this->checkLogin();
         // 接收参数
-        $isCart							= request('is_cart',0);
         $productList					= request('product_list','[]');
-        $customCouponId					= request('custom_coupon_id',0);
         $addrId							= request('addr_id',0);
         $regimentId					    = request('regiment_id',0);
         $regimentActiveId				= request('regiment_active_id',0);
@@ -685,6 +683,7 @@ class Orders extends Api{
         $pid 							= $City->getOne($cityId,'pid');
 		// 如果上级不是省份
 		if( strlen($cityId) > 4  )		$pid = (int) $City->getOne($pid,'pid');
+		// 获取省份
         $province						= $City->getOne($pid,'name');
 		// 如果不是海南,
 		if( $province != '海南省' )		{
@@ -694,9 +693,8 @@ class Orders extends Api{
 			if( trim($addr['contact_province']) != trim($province) ) return json_send(['code'=>'error','msg'=>'收货地址请选择海南范围','data'=>['error'=>'收货地址需与您所选城市一致']]);
 		}
         //获取团活动信息
-        $regimentActiveInfo             = RegimentActive::query()
-            ->where([['id','=',$regimentActiveId],['status','=',1],['start_time','<=',$time],['end_time','>=',$time]])
-            ->first();
+        $regimentActiveInfo             = RegimentActive::query()->where([['id','=',$regimentActiveId],['status','=',1],['start_time','<=',$time],['end_time','>=',$time]])->first();
+		// 拼团结果
         if (!$regimentActiveInfo)       return json_send(['code'=>'error','msg'=>'拼团活动不存在','data'=>['error'=>'拼团活动不存在']]);
         //是否符合开团条件
         if($btnType == 3){
@@ -727,19 +725,15 @@ class Orders extends Api{
         }
         //查询用户参团记录
         $regimentRecordCount             = RegimentRecord::query()
-            ->where([['custom_uid','=',$uid],['active_id','=',$regimentActiveInfo['id']]])
-            ->count('id');
+											->where([['custom_uid','=',$uid],['active_id','=',$regimentActiveInfo['id']]])
+											->count('id');
         if ($regimentRecordCount >= $regimentActiveInfo['participation_number'])    return json_send(['code'=>'error','msg'=>'该活动每人仅限参与'.$regimentActiveInfo['participation_number'].'次','data'=>['error'=>'该活动每人仅限参与'.$regimentActiveInfo['participation_number'].'次']]);
-
+		// 标签信息
         $tags							= $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
         // 查询产品信息
         $productList					= $Product->getListByIds(array_column($buyList,'product_id'));
         // 当前时间
         $time 							= time();
-        // 产品以店铺分组,方便写入订单
-        $orderProduct					= [];
-        // 产品价格同级,用于优惠券计算
-        $productPrice					= [];
         $priceTotal					    = 0;
         $payTotal					    = 0;
         $buyInfo                        = $buyList[0];
@@ -844,7 +838,7 @@ class Orders extends Api{
                     'active_id'     =>  $regimentActiveInfo['id'],
                     'product_id'    =>  $buyInfo['product_id'],
                     'people_number' =>  1,
-                    'status'        =>  0,
+                    'status'        =>  1,
                     'start_time'    =>  $time,
                     'end_time'      =>  $time + $regimentActiveInfo['expiration']*3600,
                     'update_time'   =>  $time,
@@ -889,6 +883,16 @@ class Orders extends Api{
                 // 提示信息
                 return				json_send(['code'=>'error','msg'=>'地址写入失败','data'=>['error'=>'地址写入失败']]);
             }
+			//拼团记录
+            $regimentRecordInfo       =   [
+                'custom_uid'    =>  $uid,
+                'regiment_id'   =>  $regimentId,
+                'active_id'     =>  $regimentActiveInfo['id'],
+                'product_id'    =>  $buyInfo['product_id'],
+                'order_id'      =>  $orderId,
+                'update_time'   =>  $time,
+                'insert_time'   =>  $time,
+            ];
             if($btnType == 4){
                 // 拼团人数加1
                 $inc				=   Regiment::query()->where('id','=',$regimentId)->increment('people_number',1);
@@ -896,16 +900,16 @@ class Orders extends Api{
                     // 回退数据
                     DB::rollBack();
                     // 提示信息
-                    return				json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
+                    return				json_send(['code'=>'error','msg'=>'参与拼团失败','data'=>['error'=>'参与拼团失败']]);
                 }
                 //团满
                 if ((($regimentInfo['people_number'] + 1) == $regimentActiveInfo['number']) && $regimentActiveInfo['exceed_people'] == 1) {
-                    $res            =   regiment::query()->where('id','=',$regimentId)->update(['status'=>3]);
+                    $res            =   Regiment::query()->where('id','=',$regimentId)->update(['status'=>2]);
                     if( !$res )			{
                         // 回退数据
                         DB::rollBack();
                         // 提示信息
-                        return				json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
+                        return				json_send(['code'=>'error','msg'=>'修改成团状态失败','data'=>['error'=>'参与拼团失败']]);
                     }
                     //修改订单
                     $orderRes       =   $Model::query()->where('regiment_id','=',$regimentId)->update(['status'=>'1']);
@@ -913,25 +917,36 @@ class Orders extends Api{
                         // 回退数据
                         DB::rollBack();
                         // 提示信息
-                        return				json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
+                        return		json_send(['code'=>'error','msg'=>'修改订单状态失败','data'=>['error'=>'参与拼团失败']]);
+                    }
+					// 查询拼团对应的订单
+					$orderIds       = $Model::query()->where('regiment_id','=',$regimentId)->pluck('id')->toArray();
+					// 修改这些订单的子订单状态
+					$orderProductRes = $OrdersProduct::query()->whereIn('order_id',$orderIds)->update(['status'=>'1']);
+					// 修改
+					if( !$orderProductRes )			{
+                        // 回退数据
+                        DB::rollBack();
+                        // 提示信息
+                        return		json_send(['code'=>'error','msg'=>'修改子订单状态失败','data'=>['error'=>'参与拼团失败']]);
                     }
                     //赠送积分
                     $orderList      =   $Model::query()->where('regiment_id','=',$regimentId)->get();
                     foreach ($orderList as $key => $value) {
                         if( $value['order_score'] > 0 ) $CustomScore->trade($orderInfo['custom_uid'],$value['id'],$value['order_score'],5,1);
                     }
+					// 修改所有参团中的为已成功
+					$result 		= RegimentRecord::query()->where([['regiment_id','=',$regimentId],['status','=',0]])->update(['status'=>2]);
+					if( !$result )	{
+						// 回退数据
+						DB::rollBack();
+						// 提示信息
+						return		json_send(['code'=>'error','msg'=>'创建拼团记录失败','data'=>['error'=>'创建拼团记录失败']]);
+					}
+					// 拼团成功
+					$regimentRecordInfo['status'] = 2;
                 }
             }
-            //拼团记录
-            $regimentRecordInfo       =   [
-                'custom_uid'    =>  $uid,
-                'regiment_id'   =>  $regimentId,
-                'active_id'     =>  $regimentActiveInfo['id'],
-                'product_id'    =>  $buyInfo['product_id'],
-                'order_id'      =>  $orderId,
-                'update_time'   =>  $time,
-                'insert_time'   =>  $time,
-            ];
             $result 				= RegimentRecord::query()->insert($regimentRecordInfo);
             if( !$result )			{
                 // 回退数据
@@ -947,7 +962,7 @@ class Orders extends Api{
                 'snowflake_id'  =>$orderInfo['snowflake_id'],
             ];
             // 返回结果
-            return						json_send(['code'=>'success','msg'=>'下单成功','data'=>$data]);
+            return						json_send(['code'=>'success','msg'=>'拼团成功','data'=>$data]);
             // 返回结果
         } catch (\Throwable $th) {
             // 回退数据
@@ -996,10 +1011,10 @@ class Orders extends Api{
             //开团用户取消团订单
             if ($regimentInfo['people_number'] > 1 && $regimentInfo['custom_uid'] == $uid){
                 //查询团记录
-                $regimentRecordInfo       =     RegimentRecord::query()->where([['order_id','<>',$oldData['id']],['regiment_id','=',$regimentInfo['id']],['status','=',0]])->first();
+                $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']]);
+                    $result               = Regiment::query()->where('id','=',$regimentRecordInfo['regiment_id'])->update(['custom_uid'=>$regimentRecordInfo['custom_uid'],'update_time'=>time()]);
                     if (!$result) {
                         DB::rollBack();
                         return json_send(['code'=>'error','msg'=>'取消拼团,改变开团人失败']);
@@ -1011,22 +1026,22 @@ class Orders extends Api{
                     // 回退数据
                     DB::rollBack();
                     // 提示信息
-                    return json_send(['code'=>'error','msg'=>'取消拼团失败']);
+                    return json_send(['code'=>'error','msg'=>'扣减开团成员失败']);
                 }
             }else{
-                $regimentRes            = Regiment::query()->where('id','=',$oldData['regiment_id'])->update(['status'=>1]);
+                $regimentRes            = Regiment::query()->where('id','=',$oldData['regiment_id'])->update(['status'=>1,'update_time'=>time()]);
                 if (!$regimentRes){
                     DB::rollBack();
                     return json_send(['code'=>'error','msg'=>'取消拼团失败']);
                 }
             }
             //修改拼团记录
-            $regimentRes    = RegimentRecord::query()->where([['order_id','=',$oldData['id'],]])->update(['status'=>'1']);
+            $regimentRes    = RegimentRecord::query()->where([['order_id','=',$oldData['id']]])->update(['status'=>'1','update_time'=>time()]);
             if( !$regimentRes )	{
                 // 回退数据
                 DB::rollBack();
                 // 提示信息
-                return json_send(['code'=>'error','msg'=>'取消拼团失败']);
+                return json_send(['code'=>'error','msg'=>'修改拼团记录失败']);
             }
             // 提交数据
             DB::commit();

+ 6 - 3
resources/views/admin/regiment/index.blade.php

@@ -66,14 +66,17 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							</td>
 							<td>{{$a['business_name']}}</td>
 							<td>
-								@if( $a['status'] == 1 )
+								@if( $a['status'] == 0 )
 									拼团中
 								@endif
+								@if( $a['status'] == 1 )
+									取消拼团
+								@endif
 								@if( $a['status'] == 2 )
-										拼团失败
+									拼团成功
 								@endif
 								@if( $a['status'] == 3 )
-										拼团成功
+									拼团失败
 								@endif
 							</td>
 							<td>{{date('Y/m/d H:i:s',$a['start_time'])}}</td>

+ 2 - 2
resources/views/admin/regiment_active/index.blade.php

@@ -70,7 +70,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							<td>{{$a['expiration']}}</td>
 							<td>{{$a['business_name']}}</td>
 							<td>
-								@if( $a['status'] === 2)
+								@if( $a['status'] == 2)
 								停用
 								@else
 									@if( $a['start_time'] <= time() && $a['end_time'] <= time() )
@@ -95,7 +95,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 									<a href="{{url('admin/regiment_active/copy?'.http_build_query(['id'=>$a['id']]))}}" class="btn btn-sm btn-success" >复制</a>
 								@endif
 								@if(check_auth('admin/regiment_active/set_status'))
-									@if($a['status'] === 2)
+									@if($a['status'] == 2)
 									<a data-url="{{url('admin/regiment_active/set_status?'.http_build_query(['id'=>$a['id'],'status'=>1]))}}" class="set_status btn btn-sm btn-success" >启用</a>
 									@else
 									<a data-url="{{url('admin/regiment_active/set_status?'.http_build_query(['id'=>$a['id'],'status'=>2]))}}" class="set_status btn btn-sm btn-danger" >停用</a>