@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\partner;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\partner\DailyReport;
|
||||
use addons\shopro\service\partner\DailySettleService;
|
||||
|
||||
class Daily extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new DailyReport();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
$list = $this->model->sheepFilter()->order('settle_date', 'desc')->paginate($this->request->param('list_rows', 10));
|
||||
$today = date('Y-m-d');
|
||||
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
||||
$days = \addons\shopro\service\partner\PartnerConfig::activeDays();
|
||||
$since = time() - $days * 86400;
|
||||
$result = $list->toArray();
|
||||
$cashTypes = \addons\shopro\service\partner\PartnerConfig::instantTypes();
|
||||
$cashTypes = array_merge($cashTypes, ['venue_share', 'county_share']);
|
||||
$sumCash = function ($date) use ($cashTypes) {
|
||||
return (float) \app\admin\model\shopro\partner\Reward::where('settle_date', $date)
|
||||
->where('status', 1)
|
||||
->whereIn('reward_type', $cashTypes)
|
||||
->sum('amount');
|
||||
};
|
||||
$todayCash = $sumCash($today);
|
||||
// 即时奖无 settle_date,按入账日合计
|
||||
$todayStart = strtotime($today . ' 00:00:00');
|
||||
$todayEnd = $todayStart + 86400 - 1;
|
||||
$yStart = strtotime($yesterday . ' 00:00:00');
|
||||
$yEnd = $yStart + 86400 - 1;
|
||||
$instantToday = (float) \app\admin\model\shopro\partner\Reward::where('status', 1)
|
||||
->whereNull('settle_date')
|
||||
->whereBetween('createtime', [$todayStart, $todayEnd])
|
||||
->whereIn('reward_type', \addons\shopro\service\partner\PartnerConfig::instantTypes())
|
||||
->sum('amount');
|
||||
$instantYesterday = (float) \app\admin\model\shopro\partner\Reward::where('status', 1)
|
||||
->whereNull('settle_date')
|
||||
->whereBetween('createtime', [$yStart, $yEnd])
|
||||
->whereIn('reward_type', \addons\shopro\service\partner\PartnerConfig::instantTypes())
|
||||
->sum('amount');
|
||||
$result['kpi'] = [
|
||||
'today' => DailyReport::where('settle_date', $today)->find(),
|
||||
'yesterday' => DailyReport::where('settle_date', $yesterday)->find(),
|
||||
'today_cash' => number_format($todayCash + $instantToday, 2, '.', ''),
|
||||
'yesterday_cash' => number_format($sumCash($yesterday) + $instantYesterday, 2, '.', ''),
|
||||
'inactive_count' => \app\admin\model\shopro\commission\Agent::where(function ($q) use ($since) {
|
||||
$q->whereNull('last_self_order_time')->whereOr('last_self_order_time', '<', $since);
|
||||
})->count(),
|
||||
];
|
||||
$this->success('获取成功', null, $result);
|
||||
}
|
||||
|
||||
public function rerun()
|
||||
{
|
||||
$date = $this->request->param('settle_date');
|
||||
if (!$date) {
|
||||
$this->error('请选择日期');
|
||||
}
|
||||
$report = (new DailySettleService())->run($date, true);
|
||||
$this->success('重跑完成', null, $report);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户