@@ -12,7 +12,7 @@ use think\Db;
|
||||
|
||||
class Agent extends Common
|
||||
{
|
||||
protected $noNeedRight = ['select'];
|
||||
protected $noNeedRight = ['select', 'identity'];
|
||||
|
||||
protected $model = null;
|
||||
|
||||
@@ -52,6 +52,28 @@ class Agent extends Common
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$amounts = \addons\shopro\service\partner\PartnerConfig::push3Amounts();
|
||||
$seq = intval($detail->direct_order_seq ?? 0);
|
||||
$next = $amounts[$seq % count($amounts)] ?? 398;
|
||||
$last = intval($detail->last_self_order_time ?? 0);
|
||||
$days = \addons\shopro\service\partner\PartnerConfig::activeDays();
|
||||
$ago = $last ? intval(floor((time() - $last) / 86400)) : null;
|
||||
$cash = \app\admin\model\shopro\partner\Reward::where('user_id', $id)
|
||||
->where('status', 1)
|
||||
->where('amount', '>', 0)
|
||||
->sum('amount');
|
||||
|
||||
$detail->next_push3_amount = number_format((float) $next, 2, '.', '');
|
||||
$detail->next_push3_text = '第 ' . ($seq + 1) . ' 单将返 ' . $detail->next_push3_amount;
|
||||
$detail->last_self_order_text = $last ? date('Y-m-d H:i:s', $last) : '从未下单';
|
||||
$detail->active_status_text = !empty($detail->active_30d)
|
||||
? '正常领取'
|
||||
: ('已暂停' . ($ago !== null ? '(距今 ' . $ago . ' 天)' : ''));
|
||||
$detail->partner_cash_income = number_format((float) $cash, 2, '.', '');
|
||||
$detail->partner_mode = \addons\shopro\service\partner\PartnerConfig::isPartnerMode() ? 1 : 0;
|
||||
$rate = (new \addons\shopro\service\partner\RateService())->currentRate();
|
||||
$detail->madow_value = \addons\shopro\service\partner\IdentityService::formatMoney((float) ($detail->madow ?? 0) * (float) $rate);
|
||||
|
||||
$this->success('分销商详情', null, $detail);
|
||||
}
|
||||
|
||||
@@ -98,7 +120,7 @@ class Agent extends Common
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$params = $this->request->only(['status', 'upgrade_lock', 'level_status', 'level', 'apply_info']);
|
||||
$params = $this->request->only(['status', 'upgrade_lock', 'level_status', 'level', 'apply_info', 'is_venue', 'is_county', 'county_code']);
|
||||
|
||||
$result = Db::transaction(function () use ($id, $params) {
|
||||
$row = $this->model->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])->where('user_id', $id)->find();
|
||||
@@ -117,6 +139,14 @@ class Agent extends Common
|
||||
case 'level': // 修改等级
|
||||
return $this->changeLevel($row, $value);
|
||||
break;
|
||||
case 'is_venue':
|
||||
case 'is_county':
|
||||
case 'county_code':
|
||||
$result = $row->save([$field => $value]);
|
||||
if ($result) {
|
||||
LogModel::add($row->user_id, 'agent', ['type' => 'identity', 'field' => $field, 'value' => $value]);
|
||||
}
|
||||
return $result;
|
||||
default:
|
||||
return $row->save([$field => $value]);
|
||||
}
|
||||
@@ -129,6 +159,91 @@ class Agent extends Common
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开通 / 调整身份(弹窗一次提交)
|
||||
*/
|
||||
public function identity($id = null)
|
||||
{
|
||||
if (!$this->auth->check('shopro/commission/agent/edit')) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
$params = $this->request->only(['level', 'is_venue', 'is_county', 'county_code', 'upgrade_lock', 'remark']);
|
||||
if ($id === null || $id === '') {
|
||||
$this->error('请选择用户');
|
||||
}
|
||||
|
||||
$level = intval($params['level'] ?? 0);
|
||||
if ($level < 1 || $level > 7) {
|
||||
$this->error('请选择品酒师或创客等级');
|
||||
}
|
||||
$isVenue = intval($params['is_venue'] ?? 0) ? 1 : 0;
|
||||
$isCounty = intval($params['is_county'] ?? 0) ? 1 : 0;
|
||||
$countyCode = trim((string) ($params['county_code'] ?? ''));
|
||||
if ($isCounty && $countyCode === '') {
|
||||
$this->error('开通区县代理时请选择区县');
|
||||
}
|
||||
if (!$isCounty) {
|
||||
$countyCode = '';
|
||||
}
|
||||
$upgradeLock = array_key_exists('upgrade_lock', $params) ? intval($params['upgrade_lock']) : null;
|
||||
$remark = trim((string) ($params['remark'] ?? ''));
|
||||
|
||||
$result = Db::transaction(function () use ($id, $level, $isVenue, $isCounty, $countyCode, $upgradeLock, $remark) {
|
||||
$service = new AgentService(intval($id));
|
||||
if (!$service->user) {
|
||||
$this->error('未找到该用户');
|
||||
}
|
||||
if (!$service->agent) {
|
||||
$service->createNewAgent('user');
|
||||
$service = new AgentService(intval($id));
|
||||
}
|
||||
$row = $service->agent;
|
||||
if (!$row) {
|
||||
$this->error('未能生成分销身份');
|
||||
}
|
||||
|
||||
$before = \addons\shopro\service\partner\IdentityService::build($row);
|
||||
$levelModel = LevelModel::find($level);
|
||||
if (!$levelModel) {
|
||||
$this->error('未找到该等级');
|
||||
}
|
||||
|
||||
$save = [
|
||||
'level' => $level,
|
||||
'is_venue' => $isVenue,
|
||||
'is_county' => $isCounty,
|
||||
'county_code' => $countyCode,
|
||||
];
|
||||
if ($upgradeLock !== null) {
|
||||
$save['upgrade_lock'] = $upgradeLock ? 1 : 0;
|
||||
}
|
||||
$row->save($save);
|
||||
|
||||
$after = \addons\shopro\service\partner\IdentityService::build($row);
|
||||
$logRemark = $remark !== ''
|
||||
? $remark
|
||||
: sprintf('将「%s」从 %s 调整为 %s。已入账收益不追溯。', $service->user->nickname ?: $id, $before['identity_text'] ?: '未开通', $after['identity_text'] ?: '-');
|
||||
LogModel::add($row->user_id, 'agent', [
|
||||
'type' => 'identity',
|
||||
'field' => 'bundle',
|
||||
'value' => $after['identity_text'],
|
||||
'before' => $before['identity_text'],
|
||||
], null, $logRemark);
|
||||
LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $levelModel]);
|
||||
(new AgentService($row->user_id))->createAsyncAgentUpgrade();
|
||||
|
||||
return [
|
||||
'identity_text' => $after['identity_text'],
|
||||
'level' => $level,
|
||||
'is_venue' => $isVenue,
|
||||
'is_county' => $isCounty,
|
||||
'county_code' => $countyCode,
|
||||
];
|
||||
});
|
||||
|
||||
$this->success('身份已更新', null, $result);
|
||||
}
|
||||
|
||||
|
||||
// 修改状态
|
||||
private function changeStatus($row, $value)
|
||||
|
||||
在新工单中引用
屏蔽一个用户