limu 1 year ago
commit d5e50d0418
  1. 42
      app/command/brand.php
  2. 22
      app/common/repositories/user/UserExtractRepository.php
  3. 110
      app/common/repositories/user/UserRepository.php
  4. 1
      app/controller/admin/user/UserExtract.php
  5. 23
      app/controller/api/Auth.php
  6. 33
      app/controller/api/user/User.php
  7. 5
      route/admin/user.php

@ -49,7 +49,7 @@ class brand extends Command
// 指令配置
$this->setName('clearCache')
->addArgument('cacheType', Argument::OPTIONAL, 'php think menu [1] / [2]')
->setDescription('各种积分转换');
->setDescription('增值积分自动转增值贡献值');
}
/**
@ -65,14 +65,14 @@ class brand extends Command
//获取所有用户
$userList = userModel::getDB()->where('status', 1)->select()->toArray();
$start = date('Y-m-d', strtotime("-1 day")).' 00:00:00';
$end = date('Y-m-d', strtotime("-1 day")).' 23:59:59';
$start = date('Y-m-d', strtotime("-1 day")) . ' 00:00:00';
$end = date('Y-m-d', strtotime("-1 day")) . ' 23:59:59';
//全网报单区流水昨日24小时的
$baodanall = StoreOrderContribute::getDB()
->where('bao_price','>',0)
->where('created_time', '>=',$start)
->where('created_time', '<=',$end)
->where('bao_price', '>', 0)
->where('created_time', '>=', $start)
->where('created_time', '<=', $end)
->sum('baodan_liushui');
//全网品宣贡献值之和
@ -82,37 +82,29 @@ class brand extends Command
foreach ($userList as $k => $v) {
try {
//用户的品宣贡献值=本人当前品宣积分÷全网品宣积分之和×全网报单流水×1%
$brandGongxian = round($v['brand_integral']/$allBrandValue*$baodanall/100,2);
$brandGongxian = round($v['brand_integral'] / $allBrandValue * $baodanall / 100, 2);
//加到log日志
ValueContributionLog::getDB()->insert([
'type' => 7,
'types_of' => 1,
'num' => $brandGongxian,
'ctime' => date('Y-m-d H:i:s'),
'memo' => '品宣积分'.$v['brand_integral'].'自动转换为品宣贡献值'.$brandGongxian,
'memo' => '品宣积分' . $v['brand_integral'] . '自动转换为品宣贡献值' . $brandGongxian,
'user_id' => $v['uid'],
]);
//用户总贡献值 = 当前总贡献值+昨日的品宣贡献值
$all_value = $brandGongxian+$v['all_value'];
$all_value = $brandGongxian + $v['all_value'];
//贡献值自动转换为超级积分 暂定1:1
$superBrand = $all_value;
// $superBrand = $all_value;
//超级积分自动转换为增值积分 按照每天的比例 这个是重点
$brandAdd = $superBrand;
// $brandAdd = $superBrand;
$user = userModel::getDB()->where('uid', $v['uid'])->find();
//品宣积分清0
$user->brand_integral = 0;
// //品宣积分清0
// $user->brand_integral = 0;
//总贡献清0
$user->all_value = 0;
//超级积分清0
$user->super_brand = 0;
//更新增值积分
$user->brand_add += $brandAdd;
$user->all_value = $all_value;
// //更新增值积分
// $user->brand_add += $brandAdd;
//天数+1
$user->super_days += 1;
$user->save();
@ -124,7 +116,7 @@ class brand extends Command
}
}
echo date('Y-m-d H:i:s').'完成';
echo date('Y-m-d H:i:s') . '完成';
}

@ -14,6 +14,7 @@ namespace app\common\repositories\user;
use app\common\repositories\BaseRepository;
use app\common\dao\user\UserExtractDao as dao;
use app\common\model\user\User as userModel;
use app\common\repositories\wechat\WechatUserRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\services\MiniProgramService;
@ -22,6 +23,7 @@ use crmeb\services\WechatService;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
use app\common\repositories\user\UserRepository;
class UserExtractRepository extends BaseRepository
{
@ -67,6 +69,8 @@ class UserExtractRepository extends BaseRepository
*/
public function getList(array $where, $page, $limit)
{
$a = UserRepository::transAdd();
echo 13;die;
$query = $this->dao->search($where)->with(['user' => function ($query) {
$query->field('uid,avatar,nickname');
}]);
@ -102,15 +106,13 @@ class UserExtractRepository extends BaseRepository
{
event('user.extract.before', compact('user', 'data'));
$userExtract = Db::transaction(function () use ($user, $data) {
if ($user['hp_value'] < (systemConfig('user_extract_min')))
if ($user['hp_value'] < ($data['extract_price']))
throw new ValidateException('生命值不足,无法提现');
if ($user['brokerage_price'] < (systemConfig('user_extract_min')))
throw new ValidateException('可提增值积分不足');
if ($data['extract_price'] < (systemConfig('user_extract_min')))
throw new ValidateException('提现金额不得小于最低额度');
if ($user['brokerage_price'] < $data['extract_price'])
throw new ValidateException('提现金额不足');
throw new ValidateException('可提增值积分不足');
if ($data['extract_type'] == 3) {
$make = app()->make(WechatUserRepository::class);
$openid = $make->idByOpenId((int)$user['wechat_user_id']);
@ -127,6 +129,12 @@ class UserExtractRepository extends BaseRepository
$data['uid'] = $user['uid'];
$data['balance'] = $brokerage_price;
//扣除生命值
$u = userModel::where('uid', $user->uid)->find();
$u->hp_value -= $data['extract_price'];
$u->save();
return $this->dao->create($data);
});
event('user.extract', compact('userExtract'));
@ -176,6 +184,12 @@ class UserExtractRepository extends BaseRepository
$user->brokerage_price = $brokerage_price;
$user->save();
}
if ($data['status'] == -1) {
//回滚生命值
$user->hp_value += $brokerage_price;
$user->save();
}
$userExtract = $this->dao->update($id, $data);
event('user.extractStatus', compact('id', 'userExtract'));
});

@ -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()
{
}

@ -69,6 +69,7 @@ class UserExtract extends BaseController
$data['admin_id'] = $this->request->adminId();
$data['status_time'] = date('Y-m-d H:i:s',time());
$this->repository->switchStatus($id,$data);
return app('json')->success('审核成功');
}

@ -59,7 +59,7 @@ class Auth extends BaseController
public function test()
{
$order = StoreOrder::getDB()->where('order_id', 9)->find()->toArray();
$order = StoreOrder::getDB()->where('order_id', 9)->find()->toArray();
$job = new OrderPartnerJob();
$res = $job->fire($order);
// $data = [
@ -199,6 +199,8 @@ class Auth extends BaseController
*/
public function auth()
{
if (systemConfig('is_phone_login') === '1') {
return app('json')->fail('请绑定手机号');
}
@ -225,6 +227,7 @@ class Auth extends BaseController
$user[1] = $userRepository->mainUser($user[1]);
$pid = $this->request->param('spread', 0);
$userRepository->bindSpread($user[1], intval($pid));
$tokenInfo = $userRepository->createToken($user[1]);
@ -417,7 +420,7 @@ class Auth extends BaseController
*/
public function register(UserAuthValidate $validate, UserRepository $repository)
{
$data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]);
$data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5'], 'tid']);
$validate->check($data);
$sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login');
if (!$sms_code)
@ -434,6 +437,18 @@ class Auth extends BaseController
$tokenInfo = $repository->createToken($user);
$repository->loginAfter($user);
//上级获得推荐分
if (!empty($data['tid'])) {
$model = ValueContributionLog::getDB();
$model->save([
'type' => 2,
'num' => env('brand.brand_integral', '100'),
'types_of' => 1,
'ctime' => date('Y-m-d H:i:s'),
'memo' => '邀请好友获得品宣积分' . env('brand.brand_integral', '100'),
]);
}
//增送品宣积分
$model = userModel::getDB();
$model->where('uid', $user->uid)->update(['brand_integral' => env('brand.brand_integral', '100')]);
@ -547,6 +562,10 @@ class Auth extends BaseController
public function authLogin()
{
$auth = $this->request->param('auth');
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
if (!$users)

@ -373,10 +373,21 @@ class User extends BaseController
{
$type = $this->request->param('type');
$list = ValueContributionLog::getDB()
->where('user_id', $this->user->uid)
->where('type', $type)
->page((int)$this->request->param('page'), $this->request->param('limit'))->select();
$query = ValueContributionLog::getDB()
->where('user_id', $this->user->uid);
if (!empty($type)) {
$query->where('type', $type);
}
$list = $query->page((int)$this->request->param('page'), $this->request->param('limit'))->select()->toArray();
$user = userModel::getDB()->where('uid', $this->user->uid)->find();
$list['user']['hp_value'] = $user->hp_value;
$list['user']['all_value'] = $user->all_value;
$list['user']['brokerage_price'] = $user->brokerage_price;
$list['user']['proportion'] = 1;
return app('json')->success($list);
}
@ -446,27 +457,27 @@ class User extends BaseController
->where('a.is_used', 1)
->where('b.mer_labels', $type);
if(!empty($this->request->param('priceSort'))){
if($this->request->param('priceSort') == 1){
if (!empty($this->request->param('priceSort'))) {
if ($this->request->param('priceSort') == 1) {
$info->order('a.price asc');
}
if($this->request->param('priceSort') == 2){
if ($this->request->param('priceSort') == 2) {
$info->order('a.price desc');
}
}
if(!empty($this->request->param('timeSort'))){
if($this->request->param('timeSort') == 1){
if (!empty($this->request->param('timeSort'))) {
if ($this->request->param('timeSort') == 1) {
$info->order('a.create_time asc');
}
if($this->request->param('timeSort') == 2){
if ($this->request->param('timeSort') == 2) {
$info->order('a.create_time desc');
}
}
if(!empty($this->request->param('keyword'))){
if (!empty($this->request->param('keyword'))) {
$info->whereLike('a.store_name', "%{$this->request->param('keyword')}%");
}

@ -35,6 +35,11 @@ Route::group(function () {
'_auth' => false,
'_form' => 'systemUserLabelCreate2',
]);
Route::get('form3', '/createForm3')->name('systemUserLabelCreateForm3')->option([
'_alias' => '贡献值转换',
'_auth' => false,
'_form' => 'systemUserLabelCreate3',
]);
Route::delete(':id', '/delete')->name('systemUserLabelDelete')->option([
'_alias' => '用户标签删除',
]);

Loading…
Cancel
Save