修改:用户登录自动成为推广员功能取消

添加:绑定上下级添加判断 - 用户已经存在邀请人,本人已经成为某个等级的分销商,上级不存在分销商等级禁止绑定上下级关系
This commit is contained in:
wuhui_zzw 2023-12-25 11:15:34 +08:00
parent 9ddfd8017c
commit df96d485c7
2 changed files with 58 additions and 49 deletions

View File

@ -31,6 +31,7 @@ use think\exception\ValidateException;
use think\facade\Cache; use think\facade\Cache;
use think\facade\Config; use think\facade\Config;
use think\facade\Db; use think\facade\Db;
use think\facade\Log;
use think\facade\Queue; use think\facade\Queue;
use think\facade\Route; use think\facade\Route;
use think\Model; use think\Model;
@ -901,48 +902,54 @@ class UserRepository extends BaseRepository
return $this->topList($key, $page, $limit) + ['position' => $this->userPosition($key, $uid)]; return $this->topList($key, $page, $limit) + ['position' => $this->userPosition($key, $uid)];
} }
/** // 绑定上下级关系
* //TODO 绑定上下级关系 public function bindSpread(User $user, int $spreadUid){
* @param User $user try{
* @param int $spreadUid // 判断:是否已经存在邀请人 || 本人已经成为某个等级的分销商
* @throws DbException if((int)$user->spread_uid > 0 || (int)$user->brokerage_level > 0) throw new \Exception('不存在邀请人或者本人已经存在分销商等级信息!');
* @author xaboy // 判断:上级是否存在账号信息
* @day 2020/6/22 $spread = $this->dao->get($spreadUid);
*/ if(!$spread) throw new \Exception('上级不存在!');
public function bindSpread(User $user, int $spreadUid) // 判断:上级所在等级是否存在推广权限
{ if((int)$spread->brokerage_level <= 0) throw new \Exception("上级不存在推广权限!");
if ($spreadUid && !$user->spread_uid && $user->uid != $spreadUid && ($spread = $this->dao->get($spreadUid)) && $spread->spread_uid != $user->uid && !$spread->cancel_time) { // 判断:是否符合绑定条件 符合进入绑定流程
$config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give']); if ($spreadUid && $user->uid != $spreadUid && $spread && $spread->spread_uid != $user->uid && !$spread->cancel_time) {
event('user.spread.before', compact('user','spreadUid')); $config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give']);
Db::transaction(function () use ($spread, $spreadUid, $user, $config) { event('user.spread.before', compact('user','spreadUid'));
$user->spread_uid = $spreadUid; Db::transaction(function () use ($spread, $spreadUid, $user, $config) {
$user->spread_time = date('Y-m-d H:i:s'); $user->spread_uid = $spreadUid;
if ($config['extension_limit'] && $config['extension_limit_day']) { $user->spread_time = date('Y-m-d H:i:s');
$user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day')); if ($config['extension_limit'] && $config['extension_limit_day']) {
} $user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day'));
$spread->spread_count++; }
if ($config['integral_user_give'] > 0 && $user->isNew) { $spread->spread_count++;
$integral = (int)$config['integral_user_give']; if ($config['integral_user_give'] > 0 && $user->isNew) {
$spread->integral += $integral; $integral = (int)$config['integral_user_give'];
app()->make(UserBillRepository::class)->incBill($spreadUid, 'integral', 'spread', [ $spread->integral += $integral;
'link_id' => $user->uid, app()->make(UserBillRepository::class)->incBill($spreadUid, 'integral', 'spread', [
'status' => 1, 'link_id' => $user->uid,
'title' => '邀请好友', 'status' => 1,
'number' => $integral, 'title' => '邀请好友',
'mark' => '邀请好友奖励' . $integral . '积分', 'number' => $integral,
'balance' => $spread->integral 'mark' => '邀请好友奖励' . $integral . '积分',
]); 'balance' => $spread->integral
} ]);
$spread->save(); }
$user->save(); $spread->save();
//TODO 推广人月榜 $user->save();
Cache::zincrby('s_top_' . date('Y-m'), 1, $spreadUid); //TODO 推广人月榜
//TODO 推广人周榜 Cache::zincrby('s_top_' . date('Y-m'), 1, $spreadUid);
Cache::zincrby('s_top_' . monday(), 1, $spreadUid); //TODO 推广人周榜
}); Cache::zincrby('s_top_' . monday(), 1, $spreadUid);
Queue::push(UserBrokerageLevelJob::class, ['uid' => $spreadUid, 'type' => 'spread_user', 'inc' => 1]); });
app()->make(UserBrokerageRepository::class)->incMemberValue($user->uid, 'member_share_num', 0); Queue::push(UserBrokerageLevelJob::class, ['uid' => $spreadUid, 'type' => 'spread_user', 'inc' => 1]);
event('user.spread', compact('user','spreadUid')); app()->make(UserBrokerageRepository::class)->incMemberValue($user->uid, 'member_share_num', 0);
event('user.spread', compact('user','spreadUid'));
}
}catch(\Exception $e){
Log::error('绑定上下级关系 - 错误:' . $e->getMessage());
return $e->getMessage();
} }
} }
@ -1151,11 +1158,11 @@ class UserRepository extends BaseRepository
{ {
if (!$user->status) throw new ValidateException('账号已被禁用'); if (!$user->status) throw new ValidateException('账号已被禁用');
// 判断:如果用户未开启推广员 则开启推广员 // 判断:如果用户未开启推广员 则开启推广员
if($user->is_promoter != 1){ // if($user->is_promoter != 1){
$user->is_promoter = 1; // $user->is_promoter = 1;
$user->promoter_time = date('Y-m-d H:i:s'); // $user->promoter_time = date('Y-m-d H:i:s');
$user->save(); // $user->save();
} // }
$user = $user->hidden(['label_id', 'group_id', 'main_uid', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_uid', 'spread_time', 'real_name', 'birthday', 'brokerage_price'])->toArray(); $user = $user->hidden(['label_id', 'group_id', 'main_uid', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_uid', 'spread_time', 'real_name', 'birthday', 'brokerage_price'])->toArray();
return [ return [

View File

@ -376,6 +376,7 @@ class Auth extends BaseController
return app('json')->success('修改成功'); return app('json')->success('修改成功');
} }
// 绑定上下级关系
public function spread(UserRepository $userRepository) public function spread(UserRepository $userRepository)
{ {
$data = $this->request->params([ $data = $this->request->params([
@ -385,8 +386,9 @@ class Auth extends BaseController
if (isset($data['spread_code']['id']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']['id']))) { if (isset($data['spread_code']['id']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']['id']))) {
$data['spread_spid'] = $info['third_id']; $data['spread_spid'] = $info['third_id'];
} }
$userRepository->bindSpread($this->request->userInfo(), intval($data['spread_spid'])); $res = $userRepository->bindSpread($this->request->userInfo(), intval($data['spread_spid']));
return app('json')->success();
return app('json')->success($res);
} }
/** /**