@@ -50,7 +50,7 @@ class Agent extends Commission
|
||||
$this->error('抱歉!您的账户已被冻结,如有疑问请联系客服', $condition, 107);
|
||||
break;
|
||||
}
|
||||
$data = $this->service->agent;
|
||||
$data = \addons\shopro\service\partner\IdentityService::attachAgent($this->service->agent);
|
||||
|
||||
$this->success('分销商信息', $data);
|
||||
}
|
||||
@@ -134,6 +134,12 @@ class Agent extends Commission
|
||||
}])
|
||||
->paginate($this->request->param('list_rows', 8));
|
||||
|
||||
$data->each(function ($user) {
|
||||
if ($user->agent) {
|
||||
$user->setRelation('agent', \addons\shopro\service\partner\IdentityService::attachAgent($user->agent));
|
||||
}
|
||||
});
|
||||
|
||||
$this->success("", $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace addons\shopro\controller\commission;
|
||||
|
||||
use think\Request;
|
||||
use app\admin\model\shopro\commission\Order as OrderModel;
|
||||
use app\admin\model\shopro\partner\Reward as PartnerReward;
|
||||
use addons\shopro\service\partner\PartnerConfig;
|
||||
|
||||
class Order extends Commission
|
||||
{
|
||||
@@ -39,6 +41,38 @@ class Order extends Commission
|
||||
$query->$type();
|
||||
}
|
||||
$data = $query->paginate($this->request->param('list_rows', 10));
|
||||
$this->attachPartnerAmount($data, $agentId);
|
||||
$this->success("", $data);
|
||||
}
|
||||
|
||||
protected function attachPartnerAmount($data, $agentId)
|
||||
{
|
||||
$orderIds = [];
|
||||
foreach ($data as $row) {
|
||||
if (!empty($row->order_id)) {
|
||||
$orderIds[] = intval($row->order_id);
|
||||
}
|
||||
}
|
||||
$sums = [];
|
||||
if ($orderIds) {
|
||||
try {
|
||||
$rows = PartnerReward::where('user_id', $agentId)
|
||||
->whereIn('order_id', $orderIds)
|
||||
->where('status', 1)
|
||||
->whereIn('reward_type', PartnerConfig::instantTypes())
|
||||
->field('order_id, sum(amount) as partner_amount')
|
||||
->group('order_id')
|
||||
->select();
|
||||
foreach ($rows as $row) {
|
||||
$sums[intval($row['order_id'])] = $row['partner_amount'];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$sums = [];
|
||||
}
|
||||
}
|
||||
foreach ($data as $row) {
|
||||
$amount = $sums[intval($row->order_id)] ?? 0;
|
||||
$row->partner_amount = $amount > 0 ? number_format($amount, 2, '.', '') : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\partner;
|
||||
|
||||
use addons\shopro\controller\commission\Commission;
|
||||
use addons\shopro\service\partner\IdentityService;
|
||||
use addons\shopro\service\partner\PartnerConfig;
|
||||
use addons\shopro\service\partner\RateService;
|
||||
use app\admin\model\shopro\partner\Reward as RewardModel;
|
||||
use app\admin\model\shopro\partner\VoucherPlan;
|
||||
|
||||
class Index extends Commission
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$userId = $this->service->user->id;
|
||||
$monthStart = strtotime(date('Y-m-01 00:00:00'));
|
||||
$monthIncome = RewardModel::where('user_id', $userId)
|
||||
->where('status', 1)
|
||||
->where('createtime', '>=', $monthStart)
|
||||
->whereIn('reward_type', array_merge(PartnerConfig::instantTypes(), ['venue_share', 'county_share']))
|
||||
->sum('amount');
|
||||
$skipCount = RewardModel::where('user_id', $userId)
|
||||
->where('status', -1)
|
||||
->where('createtime', '>=', $monthStart)
|
||||
->count();
|
||||
$agent = IdentityService::attachAgent($this->service->agent);
|
||||
|
||||
$this->success('ok', [
|
||||
'month_income' => IdentityService::formatMoney($monthIncome),
|
||||
'skip_count' => intval($skipCount),
|
||||
'active_30d' => $agent['active_30d'] ?? true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function rewards()
|
||||
{
|
||||
$userId = $this->service->user->id;
|
||||
$tab = $this->request->param('tab', 'all');
|
||||
$query = RewardModel::where('user_id', $userId)->with(['buyer', 'order']);
|
||||
|
||||
$tabMap = [
|
||||
'push3' => ['push3'],
|
||||
'maker' => ['maker_diff', 'maker_peer', 'maker_overtaken'],
|
||||
'venue' => ['team_venue', 'venue_peer', 'venue_share'],
|
||||
'county' => ['team_county', 'county_peer', 'county_share'],
|
||||
'share' => ['venue_share', 'county_share', 'madow_share'],
|
||||
];
|
||||
if ($tab !== 'all' && isset($tabMap[$tab])) {
|
||||
$query->whereIn('reward_type', $tabMap[$tab]);
|
||||
}
|
||||
|
||||
$list = $query->order('id', 'desc')->paginate($this->request->param('list_rows', 10));
|
||||
$rows = [];
|
||||
foreach ($list as $item) {
|
||||
$reason = $item->skip_reason;
|
||||
$rows[] = [
|
||||
'id' => intval($item->id),
|
||||
'reward_type' => $item->reward_type,
|
||||
'reward_type_text' => $item->reward_type_text,
|
||||
'amount' => IdentityService::formatMoney($item->amount),
|
||||
'madow' => IdentityService::formatMadow($item->madow),
|
||||
'status' => intval($item->status),
|
||||
'status_text' => $item->status_text,
|
||||
'skip_reason' => $reason,
|
||||
'skip_reason_text' => $reason ? PartnerConfig::skipReasonText($reason, true) : '',
|
||||
'buyer_nickname' => $item->buyer ? ($item->buyer->nickname ?? '') : '',
|
||||
'order_id' => intval($item->order_id) > 0 ? intval($item->order_id) : 0,
|
||||
'createtime' => $item->createtime,
|
||||
'formula' => $item->formula,
|
||||
];
|
||||
}
|
||||
|
||||
$this->success('ok', [
|
||||
'total' => $list->total(),
|
||||
'per_page' => $list->listRows(),
|
||||
'current_page' => $list->currentPage(),
|
||||
'data' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
public function madow()
|
||||
{
|
||||
$userId = $this->service->user->id;
|
||||
$agent = IdentityService::attachAgent($this->service->agent);
|
||||
$logs = RewardModel::where('user_id', $userId)
|
||||
->where('reward_type', 'madow_share')
|
||||
->where('status', 1)
|
||||
->order('id', 'desc')
|
||||
->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$list = [];
|
||||
foreach ($logs as $item) {
|
||||
$list[] = [
|
||||
'id' => $item->id,
|
||||
'settle_date' => $item->settle_date,
|
||||
'madow' => IdentityService::formatMadow($item->madow),
|
||||
'gmv' => $item->ext['gmv'] ?? '',
|
||||
'share_user_count' => $item->ext['share_user_count'] ?? 0,
|
||||
'createtime' => $item->createtime,
|
||||
];
|
||||
}
|
||||
|
||||
$this->success('ok', [
|
||||
'madow' => $agent['madow'] ?? '0.00000000',
|
||||
'madow_rate' => $agent['madow_rate'] ?? IdentityService::formatRate(null),
|
||||
'madow_value' => $agent['madow_value'] ?? '0.00',
|
||||
'list' => $list,
|
||||
]);
|
||||
}
|
||||
|
||||
public function voucher()
|
||||
{
|
||||
$userId = $this->service->user->id;
|
||||
$agent = IdentityService::attachAgent($this->service->agent);
|
||||
$plans = VoucherPlan::where('user_id', $userId)->order('id', 'desc')->select();
|
||||
$rows = [];
|
||||
foreach ($plans as $plan) {
|
||||
$rows[] = [
|
||||
'id' => $plan->id,
|
||||
'order_id' => $plan->order_id,
|
||||
'total_amount' => IdentityService::formatMoney($plan->total_amount),
|
||||
'daily_amount' => IdentityService::formatMoney($plan->daily_amount),
|
||||
'released_amount' => IdentityService::formatMoney($plan->released_amount),
|
||||
'released_days' => intval($plan->released_days),
|
||||
'total_days' => intval($plan->total_days),
|
||||
'start_date' => $plan->start_date,
|
||||
'status' => intval($plan->status),
|
||||
'status_text' => $plan->status_text,
|
||||
];
|
||||
}
|
||||
|
||||
$this->success('ok', [
|
||||
'voucher_total' => $agent['voucher_total'] ?? '0.00',
|
||||
'voucher_released' => $agent['voucher_released'] ?? '0.00',
|
||||
'voucher_used' => $agent['voucher_used'] ?? '0.00',
|
||||
'voucher_available' => $agent['voucher_available'] ?? '0.00',
|
||||
'plans' => $rows,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,11 @@ class User extends Common
|
||||
|
||||
$user->hidden(['password', 'salt', 'createtime', 'updatetime', 'deletetime', 'remember_token', 'login_fail', 'login_ip', 'login_time']);
|
||||
|
||||
$this->success('个人详情', $user);
|
||||
$agent = \addons\shopro\service\partner\IdentityService::findAgent($user->id);
|
||||
$partner = \addons\shopro\service\partner\IdentityService::attachProfile($agent);
|
||||
$data = array_merge($user->toArray(), $partner);
|
||||
|
||||
$this->success('个人详情', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
在新工单中引用
屏蔽一个用户