145 行
5.6 KiB
PHP
145 行
5.6 KiB
PHP
<?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,
|
|
]);
|
|
}
|
|
}
|