verify_sign(); // 检查登录 $uid = $this->checkLogin(); // 获取参数 $activeId = request('active_id',0); // 获取客户城市的数据 $data = $Active->getOne($activeId); // 如果存在的话 if( !$data ) return json_send(['code'=>'error','msg'=>'活动已下线或不存在','data'=>'']); // 查询条件 $map = []; // 判断周期 if( !empty($data['freq']) ) { if( $data['freq'] == 1 ) $map = [['insert_time','>=',now()->startOfDay()->getTimestamp()],['insert_time','<=',now()->endOfDay()->getTimestamp()]]; if( $data['freq'] == 2 ) $map = [['insert_time','>=',now()->startOfWeek()->getTimestamp()],['insert_time','<=',now()->endOfWeek()->getTimestamp()]]; if( $data['freq'] == 3 ) $map = [['insert_time','>=',now()->startOfMonth()->getTimestamp()],['insert_time','<=',now()->endOfMonth()->getTimestamp()]]; } // 获取已分享次数 $shareTotal = $Model->query()->where([['active_id','=',$activeId],['custom_uid','=',$uid]])->where($map)->count(); // 计算剩余分享次数 $data['share_last'] = ($data['join_share'] - $shareTotal <= 0 ? 0 : $data['join_share'] - $shareTotal); // 如果次数不够 if( $data['share_last'] <= 0 ) return json_send(['code'=>'error','msg'=>'您已经没有分享次数了','data'=>'']); // 记录分享 $id = $Model->add(['active_id'=>$activeId,'custom_uid'=>$uid]); // 分享成功 if( !$id ) return json_send(['code'=>'error','msg'=>'记录失败','data'=>'']); // 返回结果 return json_send(['code'=>'success','msg'=>'记录成功','data'=>['id'=>$id]]); } }