123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php namespace App\Http\Controllers\Api\Score;
- use App\Http\Controllers\Api\Api;
- use App\Models\Custom as Custom;
- use App\Models\Score\Clockin as Model;
- use App\Models\Score\ClockinActive as ClockinActive;
- use App\Models\WeiBan\Tags as WeiBanTags;
- use App\Models\CustomClockinRecord;
- use App\Models\CustomCoupon;
- use http\Env\Request;
- use Illuminate\Support\Carbon;
- /**
- * 任务-打卡
- *
- * @author 刘相欣
- *
- * */
- class Clockin extends Api
- {
- /**
- * 列表 /api/score_clockin/get_list
- *
- */
- public function get_list(Model $Model,CustomCoupon $CustomCoupon, Custom $Custom, ClockinActive $ClockinActive, WeiBanTags $WeiBanTags, CustomClockinRecord $CustomClockinRecord)
- {
- // 接口验签
- // $this->verify_sign();
- // 验证登录
- $uid = $this->checkLogin();
- // 获取客户信息
- $custom = $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,$activeInfo['id']);
- $isMark['finish_day'] = empty($isMark['finish_day'])?0:$isMark['finish_day'];
- // 循环处理
- foreach ( $list as $key => $value ) {
- // 是否已经有该优惠券
- if( $value['coupon_id'] ) {
- // 是否已经有该优惠券
- $result = $CustomCoupon->isHaveCoupon([$value['coupon_id']],$uid);
- // 如果有,优惠券隐藏
- if( $result ) $value['coupon_id'] = 0;
- }
- // 是否已打卡,打卡天数内(含)为已打卡
- $value['is_finish'] = $isMark['finish_day'] >= $value['what_day'] ? 1 : 0;
- // 重新赋值
- $list[$key] = $value;
- }
- // 去除主键
- $list = array_values($list);
- $list = array_chunk($list,28);
- $data['list'] = $list;
- $data['is_mark'] = $isMark;
- $data['active_id'] = $activeInfo['id'];
- $data['start_time'] = $activeInfo['start_time'];
- $data['end_time'] = $activeInfo['end_time'];
- $data['active_rule'] = $activeInfo['active_rule'];
- // 返回结果
- return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
- }
- /**
- * 打卡 /api/score_clockin/finish
- *
- */
- public function finish(Model $Model,Custom $Custom,ClockinActive $ClockinActive,CustomClockinRecord $CustomClockinRecord)
- {
- // 接口验签
- // $this->verify_sign();
- // 验证登录
- $uid = $this->checkLogin();
- $activeId = request('active_id',0);
- // 获取客户信息
- $custom = $uid ? $Custom->getOne($uid) : [];
- //客户的城市ID 如果不存在的话
- if( !$custom['city_id'] ) return json_send(['code'=>'error','msg'=>'请选择所在城市','data'=>['error'=>'请选择所在城市']]);
- if( !$activeId ) return json_send(['code'=>'error','msg'=>'缺少活动id','data'=>['error'=>'缺少活动id']]);
- $activeInfo = $ClockinActive::query()->where(['id'=>$activeId])->first();
- 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]);
- }
- }
|