|
|
|
@ -16,6 +16,8 @@ namespace app\common\repositories\user; |
|
|
|
|
use app\common\dao\BaseDao; |
|
|
|
|
use app\common\dao\user\UserDao; |
|
|
|
|
use app\common\model\user\User; |
|
|
|
|
use app\common\model\user\User as userModel; |
|
|
|
|
use app\common\model\user\ValueContributionLog; |
|
|
|
|
use app\common\model\wechat\WechatUser; |
|
|
|
|
use app\common\repositories\BaseRepository; |
|
|
|
|
use app\common\repositories\community\CommunityRepository; |
|
|
|
@ -56,9 +58,12 @@ class UserRepository extends BaseRepository |
|
|
|
|
* UserRepository constructor. |
|
|
|
|
* @param UserDao $dao |
|
|
|
|
*/ |
|
|
|
|
public $brand_integral; |
|
|
|
|
|
|
|
|
|
public function __construct(UserDao $dao) |
|
|
|
|
{ |
|
|
|
|
$this->dao = $dao; |
|
|
|
|
$this->brand_integral = 100; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function promoter($uid) |
|
|
|
@ -103,7 +108,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
{ |
|
|
|
|
$formData = $this->dao->get($id); |
|
|
|
|
if (!$formData) throw new ValidateException('用户不存在'); |
|
|
|
|
return Elm::createForm(Route::buildUrl('systemUserChangePassword',['id' => $id])->build(), [ |
|
|
|
|
return Elm::createForm(Route::buildUrl('systemUserChangePassword', ['id' => $id])->build(), [ |
|
|
|
|
Elm::input('account', '账号', $formData->account)->disabled(true), |
|
|
|
|
Elm::password('pwd', '新密码')->required(), |
|
|
|
|
Elm::password('repwd', '确认新密码')->required(), |
|
|
|
@ -157,7 +162,6 @@ class UserRepository extends BaseRepository |
|
|
|
|
}), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Elm::radio('status', '状态', 1)->options([ |
|
|
|
|
['value' => 0, 'label' => '关闭'], |
|
|
|
|
['value' => 1, 'label' => '开启'], |
|
|
|
@ -203,7 +207,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
{ |
|
|
|
|
$query = $this->dao->search($where); |
|
|
|
|
$count = $query->count(); |
|
|
|
|
$list = $query->page($page, $limit)->setOption('field',[])->field('uid,nickname,avatar')->select(); |
|
|
|
|
$list = $query->page($page, $limit)->setOption('field', [])->field('uid,nickname,avatar')->select(); |
|
|
|
|
return compact('count', 'list'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -900,8 +904,8 @@ class UserRepository extends BaseRepository |
|
|
|
|
{ |
|
|
|
|
$moneyKey = 'b_top_' . date('Y-m'); |
|
|
|
|
$weekKey = 'b_top_' . monday(); |
|
|
|
|
Cache::zrem($weekKey,$uid); |
|
|
|
|
Cache::zrem($moneyKey,$uid); |
|
|
|
|
Cache::zrem($weekKey, $uid); |
|
|
|
|
Cache::zrem($moneyKey, $uid); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function brokerageWeekTop($uid, $page, $limit) |
|
|
|
@ -926,9 +930,10 @@ class UserRepository extends BaseRepository |
|
|
|
|
*/ |
|
|
|
|
public function bindSpread(User $user, int $spreadUid) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
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']); |
|
|
|
|
event('user.spread.before', compact('user','spreadUid')); |
|
|
|
|
event('user.spread.before', compact('user', 'spreadUid')); |
|
|
|
|
Db::transaction(function () use ($spread, $spreadUid, $user, $config) { |
|
|
|
|
$user->spread_uid = $spreadUid; |
|
|
|
|
$user->spread_time = date('Y-m-d H:i:s'); |
|
|
|
@ -936,6 +941,23 @@ class UserRepository extends BaseRepository |
|
|
|
|
$user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day')); |
|
|
|
|
} |
|
|
|
|
$spread->spread_count++; |
|
|
|
|
|
|
|
|
|
if ($user->isNew) { |
|
|
|
|
//加到log日志 |
|
|
|
|
ValueContributionLog::getDB()->insert([ |
|
|
|
|
'type' => 2, |
|
|
|
|
'types_of' => 1, |
|
|
|
|
'num' => 100, |
|
|
|
|
'ctime' => date('Y-m-d H:i:s'), |
|
|
|
|
'memo' => '邀请好友获得100品宣积分', |
|
|
|
|
'user_id' => $user->spread_uid, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$user2 = userModel::where('uid', $user->spread_uid)->find(); |
|
|
|
|
$user2->brand_integral += 100; |
|
|
|
|
$user2->save(); |
|
|
|
|
|
|
|
|
|
if ($config['integral_user_give'] > 0 && $user->isNew) { |
|
|
|
|
$integral = (int)$config['integral_user_give']; |
|
|
|
|
$spread->integral += $integral; |
|
|
|
@ -947,6 +969,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
'mark' => '邀请好友奖励' . $integral . '积分', |
|
|
|
|
'balance' => $spread->integral |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
$spread->save(); |
|
|
|
|
$user->save(); |
|
|
|
@ -957,7 +980,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
}); |
|
|
|
|
Queue::push(UserBrokerageLevelJob::class, ['uid' => $spreadUid, 'type' => 'spread_user', 'inc' => 1]); |
|
|
|
|
app()->make(UserBrokerageRepository::class)->incMemberValue($user->uid, 'member_share_num', 0); |
|
|
|
|
event('user.spread', compact('user','spreadUid')); |
|
|
|
|
event('user.spread', compact('user', 'spreadUid')); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1167,7 +1190,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
return [ |
|
|
|
|
'token' => $tokenInfo['token'], |
|
|
|
|
'exp' => $tokenInfo['out'], |
|
|
|
|
'expires_time' => strtotime('+ '.$tokenInfo['out']. 'seconds'), |
|
|
|
|
'expires_time' => strtotime('+ ' . $tokenInfo['out'] . 'seconds'), |
|
|
|
|
'user' => $user |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
@ -1272,9 +1295,9 @@ class UserRepository extends BaseRepository |
|
|
|
|
* @author Qinii |
|
|
|
|
* @day 6/9/21 |
|
|
|
|
*/ |
|
|
|
|
public function incIntegral(int $uid,int $number,$title,$type,$data) |
|
|
|
|
public function incIntegral(int $uid, int $number, $title, $type, $data) |
|
|
|
|
{ |
|
|
|
|
Db::transaction(function() use($uid,$number,$title,$type,$data){ |
|
|
|
|
Db::transaction(function () use ($uid, $number, $title, $type, $data) { |
|
|
|
|
|
|
|
|
|
$user = $this->dao->get($uid); |
|
|
|
|
$user->integral = $user->integral + $number; |
|
|
|
@ -1285,16 +1308,16 @@ class UserRepository extends BaseRepository |
|
|
|
|
[ |
|
|
|
|
'link_id' => 0, |
|
|
|
|
'status' => 1, |
|
|
|
|
'title' => $title, |
|
|
|
|
'title' => $title, |
|
|
|
|
'number' => $data['number'], |
|
|
|
|
'mark' => $data['mark'], |
|
|
|
|
'balance' =>$data['balance'], |
|
|
|
|
'mark' => $data['mark'], |
|
|
|
|
'balance' => $data['balance'], |
|
|
|
|
]); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function memberForm(int $id ,int $type) |
|
|
|
|
public function memberForm(int $id, int $type) |
|
|
|
|
{ |
|
|
|
|
if ($type) { |
|
|
|
|
$form = Elm::createForm(Route::buildUrl('systemUserMemberSave', ['id' => $id])->build()); |
|
|
|
@ -1308,7 +1331,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
if (!$data) throw new ValidateException('数据不存在'); |
|
|
|
|
if (!$type && !$data['is_promoter']) throw new ValidateException('用户不是分销员'); |
|
|
|
|
$rules = [ |
|
|
|
|
Elm::select($field, '级别',$data->$field)->options(function () use($type){ |
|
|
|
|
Elm::select($field, '级别', $data->$field)->options(function () use ($type) { |
|
|
|
|
$options = app()->make(UserBrokerageRepository::class)->options(['type' => $type])->toArray(); |
|
|
|
|
return $options; |
|
|
|
|
}), |
|
|
|
@ -1321,11 +1344,11 @@ class UserRepository extends BaseRepository |
|
|
|
|
{ |
|
|
|
|
$make = app()->make(UserBrokerageRepository::class); |
|
|
|
|
$user = $this->dao->get($id); |
|
|
|
|
$field = $type ? 'member_level' : 'brokerage_level'; |
|
|
|
|
$field = $type ? 'member_level' : 'brokerage_level'; |
|
|
|
|
if ($data[$field] == $user->$field) return true; |
|
|
|
|
$has = $make->fieldExists('brokerage_level', $data[$field], null, $type); |
|
|
|
|
if (!$has) throw new ValidateException('等级不存在'); |
|
|
|
|
Db::transaction(function() use($id, $data, $field, $user, $type){ |
|
|
|
|
Db::transaction(function () use ($id, $data, $field, $user, $type) { |
|
|
|
|
$user->$field = $data[$field]; |
|
|
|
|
if ($type) $user->member_value = 0; |
|
|
|
|
$user->save(); |
|
|
|
@ -1395,11 +1418,11 @@ class UserRepository extends BaseRepository |
|
|
|
|
Elm::switches('is_svip', '付费会员', $formData->is_svip > 0 ? 1 : 0)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'), |
|
|
|
|
]; |
|
|
|
|
if ($formData->is_svip == 3) { |
|
|
|
|
$rule[] = Elm::input('is_svip_type', '会员类型','永久会员')->disabled(true)->appendRule('suffix', [ |
|
|
|
|
$rule[] = Elm::input('is_svip_type', '会员类型', '永久会员')->disabled(true)->appendRule('suffix', [ |
|
|
|
|
'type' => 'div', |
|
|
|
|
'style' => ['color' => '#999999'], |
|
|
|
|
'domProps' => [ |
|
|
|
|
'innerHTML' =>'永久会员,若关闭后再次开启将不再是永久会员,请谨慎操作', |
|
|
|
|
'innerHTML' => '永久会员,若关闭后再次开启将不再是永久会员,请谨慎操作', |
|
|
|
|
] |
|
|
|
|
]); |
|
|
|
|
} else { |
|
|
|
@ -1411,7 +1434,7 @@ class UserRepository extends BaseRepository |
|
|
|
|
$rule[] = Elm::input('end_time', '当前有效期期限', $formData->is_svip > 0 ? $formData->svip_endtime : 0)->disabled(true); |
|
|
|
|
} |
|
|
|
|
$form->setRule($rule); |
|
|
|
|
return $form->setTitle( '编辑付费会员期限'); |
|
|
|
|
return $form->setTitle('编辑付费会员期限'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1421,45 +1444,45 @@ class UserRepository extends BaseRepository |
|
|
|
|
* @author Qinii |
|
|
|
|
* @day 2022/11/22 |
|
|
|
|
*/ |
|
|
|
|
public function svipUpdate($id, $data,$adminId) |
|
|
|
|
public function svipUpdate($id, $data, $adminId) |
|
|
|
|
{ |
|
|
|
|
$user = app()->make(UserRepository::class)->get($id); |
|
|
|
|
if (!$user) throw new ValidateException('用户不存在'); |
|
|
|
|
if ($user['is_svip'] < 1 && ($data['is_svip'] == 0 || !$data['type'])) |
|
|
|
|
if ($user['is_svip'] < 1 && ($data['is_svip'] == 0 || !$data['type'])) |
|
|
|
|
throw new ValidateException('该用户还不是付费会员'); |
|
|
|
|
if ($user['is_svip'] == 3 && $data['is_svip'] == 1) |
|
|
|
|
throw new ValidateException('该用户已是永久付费会员'); |
|
|
|
|
if ($data['is_svip']) { |
|
|
|
|
$day = ($data['type'] == 1 ? '+ ' : '- ').$data['add_time']; |
|
|
|
|
$endtime = ($user['svip_endtime'] && $user['is_svip'] != 0) ? $user['svip_endtime'] : date('Y-m-d H:i:s',time()); |
|
|
|
|
$day = ($data['type'] == 1 ? '+ ' : '- ') . $data['add_time']; |
|
|
|
|
$endtime = ($user['svip_endtime'] && $user['is_svip'] != 0) ? $user['svip_endtime'] : date('Y-m-d H:i:s', time()); |
|
|
|
|
$is_svip = 1; |
|
|
|
|
$svip_endtime = date('Y-m-d H:i:s',strtotime("$endtime $day day" )); |
|
|
|
|
$svip_endtime = date('Y-m-d H:i:s', strtotime("$endtime $day day")); |
|
|
|
|
//结束时间小于当前 就关闭付费会员 |
|
|
|
|
if (strtotime($svip_endtime) <= time()) { |
|
|
|
|
$is_svip = 0; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$is_svip = 0; |
|
|
|
|
$svip_endtime = date('Y-m-d H:i:s', time()); |
|
|
|
|
$svip_endtime = date('Y-m-d H:i:s', time()); |
|
|
|
|
} |
|
|
|
|
$make = app()->make(UserOrderRepository::class); |
|
|
|
|
$res = [ |
|
|
|
|
'title' => $data['is_svip'] == 0 ? '平台取消会员资格' : ($data['type'] ? '平台赠送' : '平台扣除'), |
|
|
|
|
'link_id' => 0, |
|
|
|
|
'order_sn' => app()->make(StoreOrderRepository::class)->getNewOrderId(StoreOrderRepository::TYPE_SN_USER_ORDER), |
|
|
|
|
'title' => $data['is_svip'] == 0 ? '平台取消会员资格' : ($data['type'] ? '平台赠送' : '平台扣除'), |
|
|
|
|
'link_id' => 0, |
|
|
|
|
'order_sn' => app()->make(StoreOrderRepository::class)->getNewOrderId(StoreOrderRepository::TYPE_SN_USER_ORDER), |
|
|
|
|
'pay_price' => 0, |
|
|
|
|
'order_info' => json_encode($data,JSON_UNESCAPED_UNICODE), |
|
|
|
|
'uid' => $id, |
|
|
|
|
'order_info' => json_encode($data, JSON_UNESCAPED_UNICODE), |
|
|
|
|
'uid' => $id, |
|
|
|
|
'order_type' => UserOrderRepository::TYPE_SVIP . $is_svip, |
|
|
|
|
'pay_type' => 'sys', |
|
|
|
|
'status' => 1, |
|
|
|
|
'pay_time' => date('Y-m-d H:i:s',time()), |
|
|
|
|
'admin_id' => $adminId, |
|
|
|
|
'end_time' => $svip_endtime, |
|
|
|
|
'other' => $user->is_svip == -1 ? 'first' : '', |
|
|
|
|
'pay_type' => 'sys', |
|
|
|
|
'status' => 1, |
|
|
|
|
'pay_time' => date('Y-m-d H:i:s', time()), |
|
|
|
|
'admin_id' => $adminId, |
|
|
|
|
'end_time' => $svip_endtime, |
|
|
|
|
'other' => $user->is_svip == -1 ? 'first' : '', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
Db::transaction(function () use($user, $res, $is_svip, $svip_endtime,$make) { |
|
|
|
|
Db::transaction(function () use ($user, $res, $is_svip, $svip_endtime, $make) { |
|
|
|
|
$make->create($res); |
|
|
|
|
$user->is_svip = $is_svip; |
|
|
|
|
$user->svip_endtime = $svip_endtime; |
|
|
|
@ -1469,21 +1492,22 @@ class UserRepository extends BaseRepository |
|
|
|
|
|
|
|
|
|
public function updateBaseInfo($data, $user) |
|
|
|
|
{ |
|
|
|
|
Db::transaction(function() use($data, $user){ |
|
|
|
|
Db::transaction(function () use ($data, $user) { |
|
|
|
|
$user->save(array_filter([ |
|
|
|
|
'nickname' => $data['nickname'] ?? '', |
|
|
|
|
'avatar' => $data['avatar'] ?? '', |
|
|
|
|
'avatar' => $data['avatar'] ?? '', |
|
|
|
|
])); |
|
|
|
|
if (isset($user->wechat) ) { |
|
|
|
|
if (isset($user->wechat)) { |
|
|
|
|
$user->wechat->save(array_filter([ |
|
|
|
|
'nickname' => $data['nickname'] ?? '', |
|
|
|
|
'nickname' => $data['nickname'] ?? '', |
|
|
|
|
'headimgurl' => $data['avatar'] ?? '', |
|
|
|
|
])); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function transAdd($num,$uid) |
|
|
|
|
//wmc |
|
|
|
|
public function transAdd() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|