Compare commits

..

2 Commits

Author SHA1 Message Date
ztt edc3da4d48 1 8 months ago
ztt acb4ecbe0d 1 8 months ago
  1. 2
      addons/shopro/controller/user/User.php
  2. 13
      addons/shopro/service/CommissionScoreLog.php
  3. 48
      application/admin/controller/shopro/user/User.php
  4. 2
      application/admin/model/shopro/user/WalletLog.php
  5. 22
      application/admin/view/shopro/user/user/detail.html

@ -161,7 +161,7 @@ class User extends Common
//如果已经有账号则直接登录
$ret = $this->auth->direct($user->id);
}else {
$ret = $this->auth->register($params['mobile'], Random::alnum(), '', $params['mobile'], ['parent_user_id'=>$parent_user_id]);
$ret = $this->auth->register($params['mobile'], Random::alnum(), '', $params['mobile'], ['parent_user_id'=>$parent_user_id, 'user_code' => Random::alnum(8)]);
$user = $this->auth->getUserinfo();
//写入分销表
AgentModel::create([

@ -106,11 +106,13 @@ class CommissionScoreLog
//1.非用户角色下单立即反积分
if ($initLevel > self::LEVEL_1 && $currentCommissionLevel == 1) {
$amount = bcsub($order['goods_price'], $current_level_price, 2);
$amount = bcmul($amount, $order['goods_num'], 2);
//算积分
Wallet::change($currentAgent->user->id, 'score', $amount, 'back_score', [], '下单返现');
//如果没有上级 给公司账户返积分
if(empty($parentUserId)) {
$this->calcCompany($current_level_price, $company_level_price);
$this->calcCompany($current_level_price, $company_level_price, $order);
}
}
@ -153,6 +155,7 @@ class CommissionScoreLog
\think\Log::info('当前商品价格'.$current_level_price);
if (!empty($amount) && $amount> 0) {
//算积分
$amount = bcmul($amount, $order['goods_num'], 2);
Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
}
}
@ -164,8 +167,9 @@ class CommissionScoreLog
if ($level5 == 0) {
$amount = bcmul($order['goods_price'], '0.02', 2);
$this->calcCompany($parent_level_price, $company_level_price, $amount);
$this->calcCompany($parent_level_price, $company_level_price, $order, $amount);
//算积分
$amount = bcmul($amount, $order['goods_num'], 2);
Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
}
$level5++;
@ -184,7 +188,7 @@ class CommissionScoreLog
} else {
//7.只有最后一级是高级时反公司积分
if ($currentLevel == self::LEVEL_5 && $sonLevel != self::LEVEL_5 && $currentCommissionLevel > 1) {
$this->calcCompany($current_level_price, $company_level_price);
$this->calcCompany($current_level_price, $company_level_price, $order);
}
return true;
}
@ -195,12 +199,13 @@ class CommissionScoreLog
* @param $order
* 公司账户算佣金
*/
public function calcCompany($currentPrice, $companyPrice, $amountRate = 0) {
public function calcCompany($currentPrice, $companyPrice, $order, $amountRate = 0) {
$amount = bcsub($currentPrice, $companyPrice, 2);
//同级奖励佣金 算差额
if ($amountRate > 0) {
$amount = bcsub($amount, $amountRate, 2);
}
$amount = bcmul($amount, $order['goods_num'], 2);
Wallet::change(2, 'score', $amount, 'team_order', [], '用户下单');
}

@ -3,6 +3,7 @@
namespace app\admin\controller\shopro\user;
use app\admin\model\shopro\commission\Agent;
use app\admin\model\shopro\commission\Agent as AgentModel;
use app\admin\model\shopro\commission\Level;
use think\Db;
use app\admin\controller\shopro\Common;
@ -38,7 +39,7 @@ class User extends Common
// dd($user_info);
$agent = Agent::with('level_info')->where('user_id', $row['id'])->find();
if (!empty($agent)) {
$row['user_level'] = $agent['level_info']['name'];
$row['user_level'] = $agent['level_info']['name']??"";
}
if ($row['parent_user_id'] > 0) {
@ -120,6 +121,24 @@ class User extends Common
$this->error(__('No Results were found'));
}
$level_list = (new Level())->select();
$new_level_list = [];
$userLevel = Agent::where('user_id', $user->id)->value('level') ?? 0;
foreach ($level_list as $level) {
$disabled = false;
if ($userLevel >= $level['level']) {
$disabled = true;
}
$new_level_list[] = [
'value' => $level['level'],
'label' => $level['name'],
'disabled' => $disabled
];
}
$user['levelList'] = $new_level_list;
$user['userLevel'] = $userLevel;
$this->success('获取成功', null, $user);
}
@ -136,16 +155,37 @@ class User extends Common
if (empty($params['password'])) unset($params['password']);
if (empty($params['username'])) unset($params['username']);
$userLevel = $this->request->param('userLevel');
$params['id'] = $id;
$this->svalidate($params, '.edit');
// $this->svalidate($params, '.edit');
unset($params['id']);
$user = $this->model->where('id', $id)->find();
$user->save($params);
$userTotalConsume = Level::get($userLevel)->total_consume ?? 0;
$agent = Agent::get(['user_id' => $id]);
if (!empty($agent)) {
if ($userLevel > $agent->level) {
$agent->level = $userLevel;
$agent->save();
$params['total_consume'] = $userTotalConsume;
}
} else {
//写入分销表
AgentModel::create([
'user_id' => $user['id'],
'level' => $userLevel, // 默认分销商等级
'status' => 'normal',
'apply_info' => [],
'apply_num' => 1,
'become_time' => time()
]);
$params['total_consume'] = $userTotalConsume;
}
$user->save($params);
$this->success('更新成功', null, $user);
}
/**
* 删除用户(支持批量)
*

@ -86,7 +86,7 @@ class WalletLog extends Common
}
public function agent()
{
return $this->belongsTo(Agent::class, 'user_id', 'user_id')->setEagerlyType(0);
return $this->belongsTo(Agent::class, 'user_id', 'user_id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{

@ -153,6 +153,22 @@
</el-radio-group>
</div>
</el-col>
<el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24">
<div class="left">设置等级</div>
<div class="right">
<el-select v-model="state.detail.userLevel" placeholder="请选择等级" style="width: 240px">
<el-option
v-for="item in state.detail.levelList"
:key="item.value"
:label="item.label"
:value="item.value"
:disabled="item.disabled">
</el-option>
</el-select>
</el-select>
</div>
</el-col>
<el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24">
<div class="label"></div>
<div class="right sa-flex sa-row-right">
@ -226,6 +242,12 @@
<div class="left">注册时间</div>
<div class="right">{{ state.detail.createtime }}</div>
</el-col>
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
<div class="left">邀请码</div>
<div class="right">
{{ state.detail.user_code }}
</div>
</el-col>
</el-row>
</div>
</div>

Loading…
Cancel
Save