|
@@ -2,7 +2,6 @@
|
|
|
|
|
|
use App\Http\Controllers\Api\Api;
|
|
|
use App\Models\Lottery\Recruitment as Model;
|
|
|
-use App\Models\Lottery\RecruitmentUsable;
|
|
|
use App\Models\Custom;
|
|
|
use App\Models\CustomCoupon;
|
|
|
use App\Models\CustomScore;
|
|
@@ -25,54 +24,70 @@ class Recruitment extends Api{
|
|
|
*
|
|
|
*
|
|
|
* */
|
|
|
- public function get_detail(Model $Model,Custom $Custom,RecruitmentReward $RecruitmentReward,RecruitmentUsable $RecruitmentUsable,WeiBanTags $WeiBanTags){
|
|
|
+ public function get_detail(Model $Model,Custom $Custom,RecruitmentReward $RecruitmentReward,RecruitmentRecord $RecruitmentRecord,WeiBanTags $WeiBanTags){
|
|
|
// 接口验签
|
|
|
// $this->verify_sign();
|
|
|
// 检查登录
|
|
|
$uid = $this->checkLogin();
|
|
|
- // 获取客户信息
|
|
|
- $custom = $Custom->getOne($uid);
|
|
|
- // 如果存在的话
|
|
|
- if( !$custom ) return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
|
|
|
// 接收参数
|
|
|
$id = request('id',0);
|
|
|
// 获取活动
|
|
|
$data = $Model->getOne($id);
|
|
|
// 如果存在的话
|
|
|
if( !$data ) return json_send(['code'=>'error','msg'=>'暂无活动','data'=>$data]);
|
|
|
- // 默认可以参加活动
|
|
|
- $data['allow_join'] = 1;
|
|
|
+ // 获取客户信息
|
|
|
+ $custom = $Custom->getOne($uid);
|
|
|
+ // 如果存在的话
|
|
|
+ if( !$custom ) return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
|
|
|
+ // 如果客户注册时间不在活动期间
|
|
|
+ if( $data['start_time'] > $custom['insert_time'] || $data['end_time'] < $custom['insert_time'] ) return json_send(['code'=>'error','msg'=>'账号不在活动范围','data'=>['error'=>'不在活动时间内注册']]);
|
|
|
+ // 如果城市限制并且不在在城市范围内,不允许参加
|
|
|
+ if ( $data['city_ids'] && !in_array($custom['city_id'],explode(',',$data['city_ids'])) ) return json_send(['code'=>'error','msg'=>'账号不在城市范围,请核对您的城市','data'=>['error'=>'不在标签范围内']]);
|
|
|
// 判断是不是可以参与
|
|
|
if( $data['tag_scope'] ) {
|
|
|
// 解析数组
|
|
|
$data['tag_scope'] = explode(',',$data['tag_scope']);
|
|
|
// 查询用户标签
|
|
|
$tags = $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
|
|
|
- // 标签范围限定时,默认不能参与
|
|
|
- $data['allow_join'] = 0;
|
|
|
- // 判断标签是不是存在
|
|
|
- foreach ($tags as $value) {
|
|
|
- // 标签范围内,允许参加
|
|
|
- if( in_array($value['name'],$data['tag_scope']) ) $data['allow_join'] = 1;
|
|
|
+ // 获取用户的标签
|
|
|
+ $tags = array_column($tags,'name');
|
|
|
+ $intersect = count(array_intersect($data['tag_scope'],$tags));
|
|
|
+ // 判断标签是否必须同时满足
|
|
|
+ if( $data['tag_scope_type'] == 1 ) {
|
|
|
+ // 判断用户的标签是否全部满足于标签限制范围内
|
|
|
+ if( $intersect != count($data['tag_scope']) ) return json_send(['code'=>'error','msg'=>'账号不在标签范围','data'=>['error'=>'不在标签范围内']]);
|
|
|
+ }else{
|
|
|
+ // 判断标签限制并且不在标签限制范围内,不允许参加
|
|
|
+ if( !$intersect ) return json_send(['code'=>'error','msg'=>'账号不在标签范围','data'=>['error'=>'不在标签范围内']]);
|
|
|
}
|
|
|
- // 如果不能参与
|
|
|
- if( !$data['allow_join'] ) return json_send(['code'=>'error','msg'=>'账号不在标签范围','data'=>['error'=>'不在标签范围内']]);
|
|
|
- }
|
|
|
- // 判断是不是可以参与
|
|
|
- if( $data['city_ids'] ) {
|
|
|
- // 解析数组
|
|
|
- $data['city_ids'] = explode(',',$data['city_ids']);
|
|
|
- // 如果不在城市范围
|
|
|
- if( !in_array($custom['city_id'],$data['city_ids']) ) $data['allow_join'] = 0;
|
|
|
- // 如果不能参与
|
|
|
- if( !$data['allow_join'] ) return json_send(['code'=>'error','msg'=>'账号不在活动城市','data'=>['error'=>'账号不在活动城市']]);
|
|
|
}
|
|
|
+ // 默认可以参加活动
|
|
|
+ $data['allow_join'] = 1;
|
|
|
// 奖品
|
|
|
$reward = $RecruitmentReward->getListByLottery($data['id']);
|
|
|
// 活动暂无奖品
|
|
|
if( !$reward ) return json_send(['code'=>'error','msg'=>'活动暂未配置奖品','data'=>$data]);
|
|
|
+ // 查询条件
|
|
|
+ $map = [];
|
|
|
+ // 判断周期
|
|
|
+ if( !empty($data['freq']) ) {
|
|
|
+ if( $data['freq'] == 1 ) $map = [['insert_time','>=',now()->addMinutes(-10)->getTimestamp()],['insert_time','<=',now()->endOfDay()->getTimestamp()]];
|
|
|
+ // 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()]];
|
|
|
+ }
|
|
|
// logo
|
|
|
$data['logo'] = $data['logo'] ? path_compat($data['logo']) : '';
|
|
|
+ // 查询用户已参与次数
|
|
|
+ $data['join_num'] = (int)$RecruitmentRecord->query()->where([['custom_uid','=',$uid],['lottery_id','=',$id]])->where($map)->count();
|
|
|
+ // 计算剩余次数
|
|
|
+ $data['number'] = $data['lucky_num'] - $data['join_num'];
|
|
|
+ // 最少为0,避免显示异常
|
|
|
+ $data['number'] = $data['number'] < 0 ? 0 : $data['number'];
|
|
|
+ // 时间处理
|
|
|
+ $data['start_date'] = date('Y/m/d H:i',$data['start_time']);
|
|
|
+ // 时间处理
|
|
|
+ $data['end_date'] = date('Y/m/d H:i',$data['end_time']);
|
|
|
// 通过活动ID,查询奖品
|
|
|
$data['reward_list'] = [];
|
|
|
// 奖品数据
|
|
@@ -80,14 +95,6 @@ class Recruitment extends Api{
|
|
|
// 奖项
|
|
|
$data['reward_list'][] = ['id'=>$value['id'],'name'=>$value['reward_name'],'img'=>$value['reward_thumb'],'reward_type'=>$value['reward_type']];
|
|
|
}
|
|
|
- // 查询用户可用抽奖次数
|
|
|
- $number = $RecruitmentUsable->query()->where([['custom_uid','=',$uid],['lottery_id','=',$id]])->value('number');
|
|
|
- // 最少为0,避免显示异常
|
|
|
- $data['number'] = $number < 0 ? 0 : $number;
|
|
|
- // 时间处理
|
|
|
- $data['start_date'] = date('Y/m/d H:i',$data['start_time']);
|
|
|
- // 时间处理
|
|
|
- $data['end_date'] = date('Y/m/d H:i',$data['end_time']);
|
|
|
// 返回结果
|
|
|
return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
|
|
|
}
|
|
@@ -100,56 +107,62 @@ class Recruitment extends Api{
|
|
|
// 接口验签
|
|
|
// $this->verify_sign();
|
|
|
// 检查登录
|
|
|
- $uid = $this->checkLogin();
|
|
|
+ $uid = $this->checkLogin();
|
|
|
// 获取活动
|
|
|
- $lotteryId = request('lottery_id',0);
|
|
|
+ $lotteryId = request('lottery_id',0);
|
|
|
// 如果存在的话
|
|
|
- if( !$lotteryId ) return json_send(['code'=>'error','msg'=>'请选择参与的活动','data'=>['error'=>"抽奖活动ID有误"]]);
|
|
|
+ if( !$lotteryId ) return json_send(['code'=>'error','msg'=>'请选择参与的活动','data'=>['error'=>"抽奖活动ID有误"]]);
|
|
|
// 获取客户信息
|
|
|
- $custom = $Custom->getOne($uid);
|
|
|
+ $custom = $Custom->getOne($uid);
|
|
|
// 如果存在的话
|
|
|
- if( !$custom ) return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
|
|
|
+ if( !$custom ) return json_send(['code'=>'no_login','msg'=>'请登录','data'=>['error'=>'无对应客户']]);
|
|
|
// 通过活动ID,查询奖品
|
|
|
- $data = $Model->getOne($lotteryId);
|
|
|
+ $data = $Model->getOne($lotteryId);
|
|
|
// 如果存在的话
|
|
|
- if( !$data ) return json_send(['code'=>'error','msg'=>'活动不存在或未开始','data'=>$data]);
|
|
|
+ if( !$data ) return json_send(['code'=>'error','msg'=>'活动不存在或未开始','data'=>$data]);
|
|
|
// 活动时间判断
|
|
|
- if( $data['start_time'] > time() ) return json_send(['code'=>'error','msg'=>'活动暂未开始','data'=>$data]);
|
|
|
+ if( $data['start_time'] > time() ) return json_send(['code'=>'error','msg'=>'活动暂未开始','data'=>$data]);
|
|
|
// 活动时间判断
|
|
|
- if( $data['end_time'] < time() ) return json_send(['code'=>'error','msg'=>'活动已结束','data'=>$data]);
|
|
|
- // 默认可以参加活动
|
|
|
- $data['allow_join'] = 1;
|
|
|
+ if( $data['end_time'] < time() ) return json_send(['code'=>'error','msg'=>'活动已结束','data'=>$data]);
|
|
|
+ // 如果客户注册时间不在活动期间
|
|
|
+ if( $data['start_time'] > $custom['insert_time'] || $data['end_time'] < $custom['insert_time'] ) return json_send(['code'=>'error','msg'=>'账号不在活动范围','data'=>['error'=>'不在活动时间内注册']]);
|
|
|
+ // 如果城市限制并且不在在城市范围内,不允许参加
|
|
|
+ if ( $data['city_ids'] && !in_array($custom['city_id'],explode(',',$data['city_ids'])) ) return json_send(['code'=>'error','msg'=>'账号不在城市范围,请核对您的城市','data'=>['error'=>'不在标签范围内']]);
|
|
|
// 判断是不是可以参与
|
|
|
if( $data['tag_scope'] ) {
|
|
|
// 解析数组
|
|
|
$data['tag_scope'] = explode(',',$data['tag_scope']);
|
|
|
// 查询用户标签
|
|
|
$tags = $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
|
|
|
- // 标签范围限定时,默认不能参与
|
|
|
- $data['allow_join'] = 0;
|
|
|
- // 判断标签是不是存在
|
|
|
- foreach ($tags as $value) {
|
|
|
- // 标签范围内,允许参加
|
|
|
- if( in_array($value['name'],$data['tag_scope']) ) $data['allow_join'] = 1;
|
|
|
+ // 获取用户的标签
|
|
|
+ $tags = array_column($tags,'name');
|
|
|
+ $intersect = count(array_intersect($data['tag_scope'],$tags));
|
|
|
+ // 判断标签是否必须同时满足
|
|
|
+ if( $data['tag_scope_type'] == 1 ) {
|
|
|
+ // 判断用户的标签是否全部满足于标签限制范围内
|
|
|
+ if( $intersect != count($data['tag_scope']) ) return json_send(['code'=>'error','msg'=>'账号不在标签范围','data'=>['error'=>'不在标签范围内']]);
|
|
|
+ }else{
|
|
|
+ // 判断标签限制并且不在标签限制范围内,不允许参加
|
|
|
+ if( !$intersect ) return json_send(['code'=>'error','msg'=>'账号不在标签范围','data'=>['error'=>'不在标签范围内']]);
|
|
|
}
|
|
|
- // 如果不能参与
|
|
|
- if( !$data['allow_join'] ) return json_send(['code'=>'error','msg'=>'不符合参与条件','data'=>['error'=>'不符合参与条件']]);
|
|
|
- }
|
|
|
- // 判断是不是可以参与
|
|
|
- if( $data['city_ids'] ) {
|
|
|
- // 解析数组
|
|
|
- $data['city_ids'] = explode(',',$data['city_ids']);
|
|
|
- // 如果不在城市范围
|
|
|
- if( !in_array($custom['city_id'],$data['city_ids']) ) $data['allow_join'] = 0;
|
|
|
- // 如果不能参与
|
|
|
- if( !$data['allow_join'] ) return json_send(['code'=>'error','msg'=>'账号不在活动城市','data'=>['error'=>'账号不在活动城市']]);
|
|
|
}
|
|
|
+ // 默认可以参加活动
|
|
|
+ $data['allow_join'] = 1;
|
|
|
// 奖品
|
|
|
$reward = $RecruitmentReward->getListByLottery($data['id']);
|
|
|
// 活动暂无奖品
|
|
|
if( !$reward ) return json_send(['code'=>'error','msg'=>'活动暂未配置奖品','data'=>$data]);
|
|
|
+ // 查询条件
|
|
|
+ $map = [];
|
|
|
+ // 判断周期
|
|
|
+ if( !empty($data['freq']) ) {
|
|
|
+ if( $data['freq'] == 1 ) $map = [['insert_time','>=',now()->addMinutes(-10)->getTimestamp()],['insert_time','<=',now()->endOfDay()->getTimestamp()]];
|
|
|
+ // 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()]];
|
|
|
+ }
|
|
|
// 查询用户已参与次数
|
|
|
- $data['join_num'] = (int)$RecruitmentRecord->query()->where([['custom_uid','=',$uid],['lottery_id','=',$lotteryId]])->count();
|
|
|
+ $data['join_num'] = (int)$RecruitmentRecord->query()->where([['custom_uid','=',$uid],['lottery_id','=',$lotteryId]])->where($map)->count();
|
|
|
// 计算剩余次数
|
|
|
$data['join_num'] = $data['lucky_num'] - $data['join_num'];
|
|
|
// 如果次数不够
|
|
@@ -159,14 +172,6 @@ class Recruitment extends Api{
|
|
|
// 开启事务
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
- // 查询条件
|
|
|
- $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()]];
|
|
|
- }
|
|
|
// 是否限制中奖次数字段,没有默认中奖一次
|
|
|
$data['max_reward'] = isset($data['max_reward']) ? 1 : $data['max_reward'];
|
|
|
// 限制中奖则获取中奖次数
|
|
@@ -230,7 +235,7 @@ class Recruitment extends Api{
|
|
|
// 写入记录
|
|
|
$result = $RecruitmentRecord->add($record);
|
|
|
// 写入失败
|
|
|
- if( !$result ) {
|
|
|
+ if( !$result ) {
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示
|