verify_sign(); // 验证登录 $uid = $this->getUid(); // 获取列表 $list = $Model->getList(); $isMark = $Model->isMarkClock($uid); $isMark['finish_day'] = empty($isMark['finish_day'])?0:$isMark['finish_day']; // 循环处理 foreach ( $list as $key => $value ) { // 是否已打卡,打卡天数内(含)为已打卡 $value['is_finish'] = $isMark['finish_day'] >= $value['what_day'] ? 1 : 0; // 重新赋值 $list[$key] = $value; } // 去除主键 $list = array_values($list); // 返回结果 return json_send(['code'=>'success','msg'=>'获取成功','data'=>['list'=>$list,'is_mark'=>$isMark]]); }*/ public function get_list(Model $Model, Custom $Custom, ClockinActive $ClockinActive, WeiBanTags $WeiBanTags, CustomClockinRecord $CustomClockinRecord) { // 接口验签 // $this->verify_sign(); // 验证登录 $uid = $this->getUid(); // 获取客户信息 $custom = $uid ? $Custom->getOne($uid) : []; //客户的城市ID 如果不存在的话 if( !$custom['city_id'] ) return json_send(['code'=>'error','msg'=>'请选择所在城市','data'=>['error'=>'请选择所在城市']]); $cityId = $custom['city_id']; // 查询用户标签 $tags = $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']); //获取打卡活动列表 $activeList = $ClockinActive->getList(); if (!$activeList) return json_send(['code'=>'error','msg'=>'暂无签到活动','data'=>['error'=>'暂无签到活动']]); $activeInfo = []; foreach ($activeList as $value){ $city_ids = $value['city_ids'] ? explode(',',$value['city_ids']) : []; $tag_scope = $value['tag_scope'] ? explode(',',$value['tag_scope']) : []; if( !$city_ids || in_array($cityId,$city_ids) ) { if ($tag_scope){ foreach ($tags as $tag) { // 标签范围内 if( in_array($tag['name'],$tag_scope) ) { $activeInfo = $value; break; } } }else{ $activeInfo = $value; break; } } } if (!$activeInfo) return json_send(['code'=>'error','msg'=>'暂无签到活动','data'=>['error'=>'暂无签到活动']]); // 获取列表 $list = $Model->getActiveList($activeInfo['id']); $isMark = $CustomClockinRecord->isMarkClock($uid); $isMark['finish_day'] = empty($isMark['finish_day'])?0:$isMark['finish_day']; // 循环处理 foreach ( $list as $key => $value ) { // 是否已打卡,打卡天数内(含)为已打卡 $value['is_finish'] = $isMark['finish_day'] >= $value['what_day'] ? 1 : 0; // 重新赋值 $list[$key] = $value; } // 去除主键 $list = array_values($list); $list = array_chunk($list,28); // 返回结果 return json_send(['code'=>'success','msg'=>'获取成功','data'=>['list'=>$list,'is_mark'=>$isMark]]); } /** * 打卡 /api/score_clockin/finish * */ public function finish(Model $Model,Custom $Custom,WeiBanTags $WeiBanTags,ClockinActive $ClockinActive,CustomClockinRecord $CustomClockinRecord) { // 接口验签 // $this->verify_sign(); // 验证登录 $uid = $this->getUid(); // 获取客户信息 $custom = $uid ? $Custom->getOne($uid) : []; //客户的城市ID 如果不存在的话 if( !$custom['city_id'] ) return json_send(['code'=>'error','msg'=>'请选择所在城市','data'=>['error'=>'请选择所在城市']]); $cityId = $custom['city_id']; // 查询用户标签 $tags = $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']); //获取打卡活动列表 $activeList = $ClockinActive->getList(); if (!$activeList) return json_send(['code'=>'error','msg'=>'暂无签到活动','data'=>['error'=>'暂无签到活动']]); $activeInfo = []; foreach ($activeList as $value){ $city_ids = $value['city_ids'] ? explode(',',$value['city_ids']) : []; $tag_scope = $value['tag_scope'] ? explode(',',$value['tag_scope']) : []; if( !$city_ids || in_array($cityId,$city_ids) ) { if ($tag_scope){ foreach ($tags as $tag) { // 标签范围内 if( in_array($tag['name'],$tag_scope) ) { $activeInfo = $value; break; } } }else{ $activeInfo = $value; break; } } } if (!$activeInfo) return json_send(['code'=>'error','msg'=>'暂无签到活动','data'=>['error'=>'暂无签到活动']]); // 获取打卡次数 $result = $CustomClockinRecord->finish($uid,$activeInfo['id']); // 失败结束 if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error'],'data'=>'']); // 返回结果 return json_send(['code'=>'success','msg'=>'打卡成功','data'=>$result]); } }