Commit a7408baf authored by 刘小敏's avatar 刘小敏

feat(agent): 添加批量修改佣金比例及代理申请校验

parent 9f18d225
...@@ -24,10 +24,16 @@ class Agent extends Common ...@@ -24,10 +24,16 @@ class Agent extends Common
$userId = $user->id ?? 0; $userId = $user->id ?? 0;
custom_log('[agent.apply] 收到代理申请请求, user_id=' . $userId, $userId, 'share'); custom_log('[agent.apply] 收到代理申请请求, user_id=' . $userId, $userId, 'share');
// 校验是否为分销商
$isDistributor = \app\admin\model\shopro\commission\Agent::where('user_id', $userId)->find();
if (!$isDistributor) {
$this->error('请先申请成为分销商');
}
$params = $this->request->only(['real_name', 'id_card', 'id_card_images']); $params = $this->request->only(['real_name', 'id_card', 'id_card_images']);
custom_log('[agent.apply] 解析参数: ' . json_encode($params, JSON_UNESCAPED_UNICODE), $userId, 'share'); custom_log('[agent.apply] 解析参数: ' . json_encode($params, JSON_UNESCAPED_UNICODE), $userId, 'share');
$this->svalidate($params, '\addons\shopro\validate\user\User.agentApply'); $this->svalidate($params, '.agentApply');
custom_log('[agent.apply] 参数校验通过', $userId, 'share'); custom_log('[agent.apply] 参数校验通过', $userId, 'share');
$service = new \addons\shopro\service\agent\ApplyService($user); $service = new \addons\shopro\service\agent\ApplyService($user);
......
...@@ -39,29 +39,16 @@ class ApplyService ...@@ -39,29 +39,16 @@ class ApplyService
throw new \think\Exception('您已是代理商,无需重复申请'); throw new \think\Exception('您已是代理商,无需重复申请');
} }
// 3. 校验省份是否已被代理 // 3. 写入申请记录
if (AgentModel::hasActiveAgent($params['province_id'])) {
throw new \think\Exception('该省份已有代理商');
}
// 4. 获取省份名称
$province = AreaModel::where('id', $params['province_id'])->where('level', 'province')->find();
if (!$province) {
throw new \think\Exception('省份不存在');
}
// 5. 写入申请记录
$apply = ApplyModel::create([ $apply = ApplyModel::create([
'user_id' => $userId, 'user_id' => $userId,
'province_id' => $params['province_id'],
'province_name' => $province->name,
'real_name' => $params['real_name'], 'real_name' => $params['real_name'],
'id_card' => $params['id_card'], 'id_card' => $params['id_card'],
'id_card_images' => $params['id_card_images'] ?? [], 'id_card_images' => $params['id_card_images'] ?? [],
'status' => ApplyModel::STATUS_PENDING, 'status' => ApplyModel::STATUS_PENDING,
]); ]);
custom_log('[agent.apply] 代理申请提交成功, apply_id=' . $apply->id . ', user_id=' . $userId . ', province=' . $province->name, $userId, 'share'); custom_log('[agent.apply] 代理申请提交成功, apply_id=' . $apply->id . ', user_id=' . $userId, $userId, 'share');
return $apply; return $apply;
} }
......
...@@ -94,6 +94,37 @@ class Agent extends Backend ...@@ -94,6 +94,37 @@ class Agent extends Backend
} }
/** /**
* 批量修改佣金比例
*/
public function batch_commission_rate()
{
if (!$this->request->isPost()) {
$this->error(__('Invalid parameters'));
}
$ids = $this->request->post('ids');
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$rate = $this->request->post('commission_rate');
if ($rate === null || $rate === '') {
$this->error('请输入佣金比例');
}
$rate = round(floatval($rate), 2);
if ($rate < 0 || $rate > 100) {
$this->error('佣金比例应在0-100之间');
}
$ids = is_array($ids) ? $ids : explode(',', $ids);
$count = $this->model->where('id', 'in', $ids)->update(['commission_rate' => $rate]);
if ($count !== false) {
$this->success("已成功更新 {$count} 条记录的佣金比例为 {$rate}%");
} else {
$this->error('更新失败');
}
}
/**
* 查看 * 查看
*/ */
public function index() public function index()
......
...@@ -22,4 +22,6 @@ return [ ...@@ -22,4 +22,6 @@ return [
'Amount' => '佣金金额', 'Amount' => '佣金金额',
'Type' => '流水类型', 'Type' => '流水类型',
'Remark' => '备注', 'Remark' => '备注',
'Batch_commission_rate' => '批量修改佣金比例',
'Please_input_commission_rate' => '请输入佣金比例(0-100)',
]; ];
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
<div class="widget-body no-padding"> <div class="widget-body no-padding">
<div id="toolbar" class="toolbar"> <div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('shopro/agent/agent/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> <!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('shopro/agent/agent/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> -->
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('shopro/agent/agent/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> <!-- <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('shopro/agent/agent/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> -->
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('shopro/agent/agent/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> <!-- <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('shopro/agent/agent/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> -->
<div class="dropdown btn-group {:$auth->check('shopro/agent/agent/multi')?'':'hide'}"> <div class="dropdown btn-group {:$auth->check('shopro/agent/agent/multi')?'':'hide'}">
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
{foreach name="statusList" item="vo"} {foreach name="statusList" item="vo"}
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:" data-params="status={$key}">{:__('Set status to ' . $key)}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:" data-params="status={$key}">{:__('Set status to ' . $key)}</a></li>
{/foreach} {/foreach}
<li role="separator" class="divider"></li>
<li><a class="btn btn-link btn-commission-rate btn-disabled disabled" href="javascript:"><i class="fa fa-percent"></i> {:__('Batch_commission_rate')}</a></li>
</ul> </ul>
</div> </div>
......
...@@ -45,6 +45,52 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -45,6 +45,52 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// 为表格绑定事件 // 为表格绑定事件
Table.api.bindevent(table); Table.api.bindevent(table);
// 批量修改佣金比例按钮
$(document).on('click', '.btn-commission-rate', function () {
var ids = Table.api.selectedids(table);
if (ids.length === 0) {
Toastr.error(lang('Please select at least one record'));
return;
}
Layer.open({
type: 1,
title: __('Batch_commission_rate'),
area: ['420px', '220px'],
content: '<div style="padding:20px 25px;">' +
'<div class="form-group">' +
'<label class="control-label">' + __('Commission_rate') + '</label>' +
'<input id="c-batch-rate" class="form-control" type="number" step="0.01" min="0" max="100" value="" placeholder="' + __('Please_input_commission_rate') + '">' +
'</div>' +
'</div>',
btn: [__('Ok'), __('Cancel')],
yes: function (index) {
var rate = $('#c-batch-rate').val();
if (rate === '' || isNaN(rate)) {
Toastr.error('请输入有效的数字');
return;
}
rate = parseFloat(rate);
if (rate < 0 || rate > 100) {
Toastr.error('佣金比例应在0-100之间');
return;
}
rate = Math.round(rate * 100) / 100;
Fast.api.ajax({
url: 'shopro/agent/agent/batch_commission_rate',
data: {
ids: ids.join(','),
commission_rate: rate
},
success: function () {
Layer.close(index);
table.bootstrapTable('refresh');
}
});
}
});
});
}, },
add: function () { add: function () {
Controller.api.bindevent(); Controller.api.bindevent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment