|
@@ -90,116 +90,121 @@ class Wechat extends Api{
|
|
|
['end_time','>',$time],
|
|
|
['status','=',0],
|
|
|
];
|
|
|
- $activeList = $RecruitmentActive::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get();
|
|
|
- $activeInfo = [];
|
|
|
- $data = [];
|
|
|
- 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;
|
|
|
+ try {
|
|
|
+ $activeList = $RecruitmentActive::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get();
|
|
|
+ $activeInfo = [];
|
|
|
+ $data = [];
|
|
|
+ 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;
|
|
|
}
|
|
|
- }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 ($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;
|
|
|
+ }
|
|
|
}
|
|
|
- if ($allowJoin) {
|
|
|
- $activeInfo = $active;
|
|
|
- break;
|
|
|
- }
|
|
|
+ }else{
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';暂无拉新活动:');
|
|
|
}
|
|
|
- }else{
|
|
|
- Log::error('recruitment','custom_uid:'.$uid.';暂无拉新活动:');
|
|
|
- }
|
|
|
- if (!empty($activeInfo)){
|
|
|
- $data['active_id'] = $activeInfo['id'];
|
|
|
- $data['old_uid'] = $shareUid;
|
|
|
- $data['new_uid'] = $uid;
|
|
|
- $data['insert_time'] = $time;
|
|
|
- $data['update_time'] = $time;
|
|
|
- //拉新记录
|
|
|
- $recordId = RecruitmentRecord::query()->insertGetId($data);
|
|
|
- if ($recordId){
|
|
|
- Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励:'.json_encode($activeInfo));
|
|
|
- //查询活动奖励配置
|
|
|
- $prizeInfo = RecruitmentActivePrize::query()->where('active_id','=',$activeInfo['id'])->first();
|
|
|
- if (!$prizeInfo) {
|
|
|
- Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励失败,无奖励配置:'.json_encode($prizeInfo));
|
|
|
- return false;
|
|
|
- }
|
|
|
- //赠送拉新奖励
|
|
|
- if ($prizeInfo['old_prize']){
|
|
|
- switch ($prizeInfo['old_prize_type']) {
|
|
|
- case 1:
|
|
|
- //赠送老用户积分
|
|
|
- $res = $this->sendScore($shareUid,$prizeInfo['old_prize'],$recordId,1);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- //赠送老用户优惠卷
|
|
|
- $res = $this->sendCoupon($shareUid,$prizeInfo['old_prize'],$recordId,1);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
|
|
|
- break;
|
|
|
+ if (!empty($activeInfo)){
|
|
|
+ $data['active_id'] = $activeInfo['id'];
|
|
|
+ $data['old_uid'] = $shareUid;
|
|
|
+ $data['new_uid'] = $uid;
|
|
|
+ $data['insert_time'] = $time;
|
|
|
+ $data['update_time'] = $time;
|
|
|
+ //拉新记录
|
|
|
+ $recordId = RecruitmentRecord::query()->insertGetId($data);
|
|
|
+ if ($recordId){
|
|
|
+ Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励:'.json_encode($activeInfo));
|
|
|
+ //查询活动奖励配置
|
|
|
+ $prizeInfo = RecruitmentActivePrize::query()->where('active_id','=',$activeInfo['id'])->first();
|
|
|
+ if (!$prizeInfo) {
|
|
|
+ Log::info('recruitment','custom_uid:'.$uid.';拉新活动赠送奖励失败,无奖励配置:'.json_encode($prizeInfo));
|
|
|
+ return false;
|
|
|
}
|
|
|
- }
|
|
|
- //赠送新用户奖励
|
|
|
- if ($prizeInfo['new_prize']){
|
|
|
- switch ($prizeInfo['new_prize_type']) {
|
|
|
- case 1:
|
|
|
- //赠送老用户积分
|
|
|
- $res = $this->sendScore($uid,$prizeInfo['new_prize'],$recordId,2);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- //赠送老用户优惠卷
|
|
|
- $res = $this->sendCoupon($uid,$prizeInfo['new_prize'],$recordId,2);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
|
|
|
- break;
|
|
|
+ //赠送拉新奖励
|
|
|
+ if ($prizeInfo['old_prize']){
|
|
|
+ switch ($prizeInfo['old_prize_type']) {
|
|
|
+ case 1:
|
|
|
+ //赠送老用户积分
|
|
|
+ $res = $this->sendScore($shareUid,$prizeInfo['old_prize'],$recordId,1);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //赠送老用户优惠卷
|
|
|
+ $res = $this->sendCoupon($shareUid,$prizeInfo['old_prize'],$recordId,1);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //赠送上级奖励
|
|
|
- if ($prizeInfo['higher_prize']){
|
|
|
- //查询上级用户
|
|
|
- $higherInfo = RecruitmentRecord::query()->where('new_uid','=',$shareUid)->first();
|
|
|
- if (!$higherInfo) return true;
|
|
|
- switch ($prizeInfo['higher_prize_type']) {
|
|
|
- case 1:
|
|
|
- //赠送上级积分
|
|
|
- $res = $this->sendScore($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- //赠送上级优惠卷
|
|
|
- $res = $this->sendCoupon($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
|
|
|
- break;
|
|
|
+ //赠送新用户奖励
|
|
|
+ if ($prizeInfo['new_prize']){
|
|
|
+ switch ($prizeInfo['new_prize_type']) {
|
|
|
+ case 1:
|
|
|
+ //赠送老用户积分
|
|
|
+ $res = $this->sendScore($uid,$prizeInfo['new_prize'],$recordId,2);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //赠送老用户优惠卷
|
|
|
+ $res = $this->sendCoupon($uid,$prizeInfo['new_prize'],$recordId,2);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ //赠送上级奖励
|
|
|
+ if ($prizeInfo['higher_prize']){
|
|
|
+ //查询上级用户
|
|
|
+ $higherInfo = RecruitmentRecord::query()->where('new_uid','=',$shareUid)->first();
|
|
|
+ if (!$higherInfo) return true;
|
|
|
+ switch ($prizeInfo['higher_prize_type']) {
|
|
|
+ case 1:
|
|
|
+ //赠送上级积分
|
|
|
+ $res = $this->sendScore($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //赠送上级优惠卷
|
|
|
+ $res = $this->sendCoupon($higherInfo['old_uid'],$prizeInfo['higher_prize'],$recordId,3);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($prizeInfo));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';拉新活动新增拉新记录失败:'.json_encode($data));
|
|
|
}
|
|
|
}else{
|
|
|
- Log::error('recruitment','custom_uid:'.$uid.';拉新活动新增拉新记录失败:'.json_encode($data));
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';无拉新活动:'.json_encode($activeInfo));
|
|
|
}
|
|
|
- }else{
|
|
|
- Log::error('recruitment','custom_uid:'.$uid.';无拉新活动:'.json_encode($activeInfo));
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';拉新活动:'.json_encode($e));
|
|
|
+ return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -253,37 +258,54 @@ class Wechat extends Api{
|
|
|
return true;
|
|
|
}
|
|
|
public function sendCoupon($uid,$prize,$recordId,$type=1){
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送优惠卷:'.json_encode($prize));
|
|
|
$time = time();
|
|
|
$Coupon = new \App\Models\Coupon();
|
|
|
$CustomCoupon = new \App\Models\CustomCoupon();
|
|
|
- // 获取优惠券的可用时间
|
|
|
- $couponData = $Coupon->query()->where([['id','=',$prize],['status','=','0']])->first(['issue_total','status','exp_time']);
|
|
|
- // 如果不存在数据,发送失败
|
|
|
- if( !$couponData || $couponData['status'] ) return 0;
|
|
|
- // 查询总共发放数量
|
|
|
- $total = $this->query()->where([['coupon_id','=',$prize]])->count();
|
|
|
- // 数量超过的话。不发
|
|
|
- if( $total >= $couponData['issue_total'] ) return 0;
|
|
|
- // 时间转时间
|
|
|
- $expTime = $Coupon->getExpTime($couponData['exp_time']);
|
|
|
- // 发送优惠券
|
|
|
- $res = $CustomCoupon->add(['coupon_id'=>$prize,'custom_uid'=>$uid,'exp_time'=>$expTime]);
|
|
|
- if (!$res) return false;
|
|
|
- //拉新奖励记录
|
|
|
- $prizeRecordInfo = [
|
|
|
- 'recruitment_record_id' => $recordId,
|
|
|
- 'custom_uid' => $uid,
|
|
|
- 'type' => $type,
|
|
|
- 'prize_type' => 1,
|
|
|
- 'prize' => $prize,
|
|
|
- 'insert_time' => $time,
|
|
|
- 'update_time' => $time,
|
|
|
- ];
|
|
|
- $res = RecruitmentPrizeRecord::query()->insertGetId($prizeRecordInfo);
|
|
|
- if (!$res){
|
|
|
- Log::error('recruitment','奖励记录失败;record:'.json_encode($prizeRecordInfo));
|
|
|
+ try {
|
|
|
+ // 获取优惠券的可用时间
|
|
|
+ $couponData = $Coupon->query()->where([['id','=',$prize],['status','=','0']])->first(['issue_total','status','exp_time']);
|
|
|
+ // 如果不存在数据,发送失败
|
|
|
+ if( !$couponData || $couponData['status'] ){
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';优惠卷奖励不存在:'.json_encode($prize));
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+ // 查询总共发放数量
|
|
|
+ $total = $this->query()->where([['coupon_id','=',$prize]])->count();
|
|
|
+ // 数量超过的话。不发
|
|
|
+ if( $total >= $couponData['issue_total'] ) {
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';优惠卷奖励超发:'.json_encode($prize));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 时间转时间
|
|
|
+ $expTime = $Coupon->getExpTime($couponData['exp_time']);
|
|
|
+ // 发送优惠券
|
|
|
+ $res = $CustomCoupon->add(['coupon_id'=>$prize,'custom_uid'=>$uid,'exp_time'=>$expTime]);
|
|
|
+ if (!$res){
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送优惠卷奖励失败:'.json_encode($prize));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //拉新奖励记录
|
|
|
+ $prizeRecordInfo = [
|
|
|
+ 'recruitment_record_id' => $recordId,
|
|
|
+ 'custom_uid' => $uid,
|
|
|
+ 'type' => $type,
|
|
|
+ 'prize_type' => 2,
|
|
|
+ 'prize' => $prize,
|
|
|
+ 'insert_time' => $time,
|
|
|
+ 'update_time' => $time,
|
|
|
+ ];
|
|
|
+ $res = RecruitmentPrizeRecord::query()->insertGetId($prizeRecordInfo);
|
|
|
+ if (!$res){
|
|
|
+ Log::error('recruitment','奖励记录失败;record:'.json_encode($prizeRecordInfo));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Log::error('recruitment','奖励优惠卷失败;record:'.json_encode($e));
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
}
|