فهرست منبع

【Fix】修复拉新活动城市区域未设置时下发异常

liuxiangxin 3 ماه پیش
والد
کامیت
d981662847
1فایلهای تغییر یافته به همراه31 افزوده شده و 56 حذف شده
  1. 31 56
      app/Http/Controllers/Api/Recruitment.php

+ 31 - 56
app/Http/Controllers/Api/Recruitment.php

@@ -22,69 +22,44 @@ class Recruitment extends Api{
      * 获取拉新活动			/api/recruitment/get_info
      * 获取拉新活动			/api/recruitment/get_info
      *
      *
      * */
      * */
-    public function get_info(Model $Model,Custom $Custom,RecruitmentPrizeRecord $RecruitmentPrizeRecord,RecruitmentRecord $RecruitmentRecord,Tags $WeiBanTags){
+    public function get_info(Model $Model,Custom $Custom,Tags $WeiBanTags){
         // 接口验签
         // 接口验签
         // $this->verify_sign();
         // $this->verify_sign();
         // 验证登录
         // 验证登录
         $uid                    		= $this->checkLogin();
         $uid                    		= $this->checkLogin();
-        // 查询数据
         // 获取客户城市ID
         // 获取客户城市ID
         $custom							= $Custom->getOne($uid);
         $custom							= $Custom->getOne($uid);
         //查询拉新活动
         //查询拉新活动
         if( !$custom['city_id'] )		return json_send(['code'=>'error','msg'=>'请选择所在城市后下单','data'=>['error'=>'请选择所在城市后下单']]);
         if( !$custom['city_id'] )		return json_send(['code'=>'error','msg'=>'请选择所在城市后下单','data'=>['error'=>'请选择所在城市后下单']]);
         // 获取城市ID
         // 获取城市ID
-        $cityId							= (string)$custom['city_id'];
+        $cityId							= $custom['city_id'];
         // 查询用户标签
         // 查询用户标签
-        $tags							= $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
-        $time                           =   time();
-        $select                         = [
-            ['start_time','<=',$time],
-            ['end_time','>',$time],
-            ['status','=',0],
-        ];
-        $activeList                     = $Model::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get()->toArray();
-        $activeInfo         =   [];
-        if ($activeList) {
-            foreach ($activeList as $active) {
-                $allowJoin = 0;
-                if ($active['tag_scope']) {
-                    // 解析数组
-                    $tag_scope = explode(',', $active['tag_scope']);
-                    // 标签范围限定时,默认不能参与
-                    // 判断标签是不是存在
-                    if ($tags) {
-                        foreach ($tags as $v) {
-                            // 标签范围内,允许参加
-                            if (in_array($v['name'], $tag_scope)) $allowJoin = 1;
-                        }
-                    }
-                }else{
-                    $allowJoin = 1;
-                }
-                if ($active['tag_except']) {
-                    // 解析数组
-                    $tag_except = explode(',', $active['tag_except']);
-                    // 标签范围限定时,默认不能参与
-                    $allowJoin = 0;
-                    // 判断标签是不是存在
-                    if ($tags) {
-                        foreach ($tags as $v) {
-                            // 标签范围内,允许参加
-                            if (in_array($v['name'], $tag_except)) $allowJoin = 0;
-                        }
-                    }
-                }
-                if ($allowJoin) {
-                    $activeInfo         =   $active;
-                    break;
-                }
-            }
+        $tagsList						= $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
+        $tagsList                       = array_column($tagsList,'name');
+        // 查询数据
+        $map                            = [['start_time','<=',time()], ['end_time','>',time()],['status','=',0]];
+        // 查询数据
+        $activeList                     = $Model->query()->where($map)->get(['id','name','banner_img','start_time','end_time','status','city_ids','tag_except','tag_scope','active_rule'])->toArray();
+        // 获取参数
+        $activeInfo                     = [];
+        // 循环处理活动数据
+        foreach ( $activeList as $active ) {
+            // 如果城市限制并且不在在城市范围内,不允许参加
+            if ( $active['city_ids'] && !in_array($cityId,explode(',',$active['city_ids'])) ) continue;
+            // 判断标签限制并且不在标签限制范围内,不允许参加
+			if( $active['tag_scope'] && !array_intersect(explode(',',$active['tag_scope']),$tagsList) ) continue;
+			// 判断标签排除限制并且在标签排除范围内,不允许参加
+			if( $active['tag_except'] && array_intersect(explode(',',$active['tag_except']),$tagsList) )  continue;
+            // 获取活动信息
+            $activeInfo                 = $active;
         }
         }
-        if ($activeInfo){
-            $activeInfo['start_time']       =   date('Y-m-d H:i:s',$activeInfo['start_time']);
-            $activeInfo['end_time']         =   date('Y-m-d H:i:s',$activeInfo['end_time']);
-            $activeInfo['banner_img']       =   path_compat($activeInfo['banner_img']);
+        // 如果存在活动信息
+        if ( $activeInfo )              {
+            $activeInfo['start_time']   = date('Y-m-d H:i:s',$activeInfo['start_time']);
+            $activeInfo['end_time']     = date('Y-m-d H:i:s',$activeInfo['end_time']);
+            $activeInfo['banner_img']   = $activeInfo['banner_img'] ? path_compat($activeInfo['banner_img']) : '';
         }
         }
+        // 返回结果
         return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$activeInfo]);
         return							json_send(['code'=>'success','msg'=>'获取成功','data'=>$activeInfo]);
     }
     }
 
 
@@ -103,11 +78,11 @@ class Recruitment extends Api{
         $map						= [['recruitment_prize_record.custom_uid','=',$uid]];
         $map						= [['recruitment_prize_record.custom_uid','=',$uid]];
         // 查询数据
         // 查询数据
         $Paginator					= $recruitmentPrizeRecord->query()
         $Paginator					= $recruitmentPrizeRecord->query()
-            ->join('recruitment_record','recruitment_record.id','=','recruitment_prize_record.recruitment_record_id')
-            ->join('custom','custom.uid','=','recruitment_record.new_uid')
-            ->where($map)
-            ->orderByDesc('id')
-            ->paginate($limit,['recruitment_prize_record.id','recruitment_prize_record.prize_type','recruitment_prize_record.prize','recruitment_prize_record.type','recruitment_prize_record.custom_uid','recruitment_prize_record.insert_time','recruitment_prize_record.recruitment_record_id','custom.username']);
+                                    ->join('recruitment_record','recruitment_record.id','=','recruitment_prize_record.recruitment_record_id')
+                                    ->join('custom','custom.uid','=','recruitment_record.new_uid')
+                                    ->where($map)
+                                    ->orderByDesc('id')
+                                    ->paginate($limit,['recruitment_prize_record.id','recruitment_prize_record.prize_type','recruitment_prize_record.prize','recruitment_prize_record.type','recruitment_prize_record.custom_uid','recruitment_prize_record.insert_time','recruitment_prize_record.recruitment_record_id','custom.username']);
         // 重置数据
         // 重置数据
         $list						= [];
         $list						= [];
         // 获取数据
         // 获取数据