|
@@ -6,6 +6,7 @@ use App\Models\City;
|
|
|
use App\Models\Custom;
|
|
|
use App\Facades\Servers\WechatMini\Mini;
|
|
|
use App\Models\RecruitmentActive;
|
|
|
+use App\Models\RecruitmentActivePrize;
|
|
|
use App\Models\RecruitmentPrizeRecord;
|
|
|
use App\Models\RecruitmentRecord;
|
|
|
use App\Models\Score\Record;
|
|
@@ -28,7 +29,7 @@ class Wechat extends Api{
|
|
|
* @param string $code 授权码
|
|
|
*
|
|
|
* */
|
|
|
- public function phone_number(Custom $Custom){
|
|
|
+ public function phone_number(Custom $Custom,Hashids $Hashids){
|
|
|
// 接口验签
|
|
|
// $this->verify_sign();
|
|
|
// 接收参数
|
|
@@ -54,6 +55,8 @@ class Wechat extends Api{
|
|
|
if( empty($custom['uid']) ) return json_send(['code'=>'error','msg'=>'注册失败,请重试','data'=>['error'=>'注册失败,请重试']]);
|
|
|
//绑定裂变邀请关系
|
|
|
if($shareUid){
|
|
|
+ $shareUid = $Hashids::decodeHex($shareUid);
|
|
|
+ Log::error('recruitment','拉新活动:'.$shareUid);
|
|
|
$this->addRecruitment($custom['uid'],$shareUid);
|
|
|
}
|
|
|
}
|
|
@@ -71,12 +74,12 @@ class Wechat extends Api{
|
|
|
$WeiBanTags = new Tags();
|
|
|
$RecruitmentActive = new RecruitmentActive();
|
|
|
// 获取客户城市ID
|
|
|
- $custom = $Custom->getOne($uid);
|
|
|
- if ($shareUid){
|
|
|
- $shareUid = Hashids::decode($shareUid);
|
|
|
- }
|
|
|
+ $custom = $Custom->getOne($shareUid);
|
|
|
//查询拉新活动
|
|
|
- if( !$custom['city_id'] ) return json_send(['code'=>'error','msg'=>'请选择所在城市后下单','data'=>['error'=>'请选择所在城市后下单']]);
|
|
|
+ if( !$custom['city_id'] ){
|
|
|
+ Log::error('recruitment','拉新活动,缺少城市:'.json_encode($custom));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
// 获取城市ID
|
|
|
$cityId = $custom['city_id'];
|
|
|
// 查询用户标签
|
|
@@ -87,7 +90,7 @@ class Wechat extends Api{
|
|
|
['end_time','>',$time],
|
|
|
['status','=',0],
|
|
|
];
|
|
|
- $activeList = $RecruitmentActive::query()->whereRaw("FIND_IN_SET('" . $cityId ."',city_ids)")->where($select)->get();
|
|
|
+ $activeList = $RecruitmentActive::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get();
|
|
|
$activeInfo = [];
|
|
|
$data = [];
|
|
|
if ($activeList) {
|
|
@@ -125,9 +128,11 @@ class Wechat extends Api{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ Log::error('recruitment','custom_uid:'.$uid.';暂无拉新活动:');
|
|
|
}
|
|
|
if (!empty($activeInfo)){
|
|
|
- $data['active_id'] = $activeInfo['id'];
|
|
|
+ $data['active_id'] = $activeInfo['id'];
|
|
|
$data['old_uid'] = $shareUid;
|
|
|
$data['new_uid'] = $uid;
|
|
|
$data['insert_time'] = $time;
|
|
@@ -135,63 +140,78 @@ class Wechat extends Api{
|
|
|
//拉新记录
|
|
|
$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 ($activeInfo['old_prize']){
|
|
|
- switch ($activeInfo['old_prize_type']) {
|
|
|
+ if ($prizeInfo['old_prize']){
|
|
|
+ switch ($prizeInfo['old_prize_type']) {
|
|
|
case 1:
|
|
|
//赠送老用户积分
|
|
|
- $res = $this->sendScore($shareUid,$activeInfo['old_prize'],$recordId,1);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($activeInfo));
|
|
|
+ $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,$activeInfo['old_prize'],$recordId,1);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($activeInfo));
|
|
|
+ $res = $this->sendCoupon($shareUid,$prizeInfo['old_prize'],$recordId,1);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prizeInfo));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
//赠送新用户奖励
|
|
|
- if ($activeInfo['new_prize']){
|
|
|
- switch ($activeInfo['new_prize_type']) {
|
|
|
+ if ($prizeInfo['new_prize']){
|
|
|
+ switch ($prizeInfo['new_prize_type']) {
|
|
|
case 1:
|
|
|
//赠送老用户积分
|
|
|
- $res = $this->sendScore($uid,$activeInfo['new_prize'],$recordId,2);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($activeInfo));
|
|
|
+ $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,$activeInfo['new_prize'],$recordId,2);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($activeInfo));
|
|
|
+ $res = $this->sendCoupon($uid,$prizeInfo['new_prize'],$recordId,2);
|
|
|
+ if (!$res) Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送新用户奖励失败:'.json_encode($prizeInfo));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
//赠送上级奖励
|
|
|
- if ($activeInfo['higher_prize']){
|
|
|
+ if ($prizeInfo['higher_prize']){
|
|
|
//查询上级用户
|
|
|
$higherInfo = RecruitmentRecord::query()->where('new_uid','=',$shareUid)->first();
|
|
|
if (!$higherInfo) return true;
|
|
|
- switch ($activeInfo['higher_prize_type']) {
|
|
|
+ switch ($prizeInfo['higher_prize_type']) {
|
|
|
case 1:
|
|
|
//赠送上级积分
|
|
|
- $res = $this->sendScore($higherInfo['old_uid'],$activeInfo['higher_prize'],$recordId,3);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($activeInfo));
|
|
|
+ $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'],$activeInfo['higher_prize'],$recordId,3);
|
|
|
- if (!$res) Log::error('recruitment','custom_uid:'.$higherInfo['old_uid'].';拉新活动赠送上级奖励失败:'.json_encode($activeInfo));
|
|
|
+ $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($activeInfo));
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
public function sendScore($uid,$prize,$recordId,$type=1){
|
|
|
$time = time();
|
|
|
- $res = CustomScore::query()->where('custom_uid','=',$uid)->increment('score',$prize);
|
|
|
+ $prize = (int)$prize;
|
|
|
+ $scoreInfo = CustomScore::query()->where('custom_uid','=',$uid)->first();
|
|
|
+ if ($scoreInfo){
|
|
|
+ $res = CustomScore::query()->where('custom_uid','=',$uid)->update(['score'=>$scoreInfo['score']+$prize,'update_time'=>$time]);
|
|
|
+ }else{
|
|
|
+ $res = CustomScore::query()->where('custom_uid','=',$uid)->insert(['custom_uid'=>$uid,'score'=>$prize,'update_time'=>$time,'insert_time'=>$time]);
|
|
|
+ }
|
|
|
if (!$res){
|
|
|
Log::error('recruitment','custom_uid:'.$uid.';拉新活动赠送老用户奖励失败:'.json_encode($prize));
|
|
|
return false;
|
|
@@ -202,7 +222,7 @@ class Wechat extends Api{
|
|
|
'balance' => $balance,
|
|
|
'buy_type' => 9,
|
|
|
'pay_type' => 1,
|
|
|
- 'description' => '老用户拉新奖励',
|
|
|
+ 'description' => '拉新奖励',
|
|
|
'status' => '1',
|
|
|
'pay_time' => $time,
|
|
|
'insert_time' => $time,
|