本地生活商家添加统计数据
This commit is contained in:
parent
c6cebd6c9d
commit
e047ce9994
@ -492,4 +492,11 @@ class LocalStore extends Api
|
||||
$size = $this->request->get('page_size', $this->page_size);
|
||||
return JsonServer::success('', LocalStoreLogic::inBindList($this->user_id, $page, $size));
|
||||
}
|
||||
|
||||
// 获取统计数据
|
||||
public function countData()
|
||||
{
|
||||
$form = $this->request->post();
|
||||
LocalStoreLogic::countData($form, $this->user_id);
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ use app\common\model\user\User;
|
||||
use app\common\server\UrlServer;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use app\common\model\localstore\LocalGoodsOrder;
|
||||
|
||||
class LocalStoreLogic extends Logic
|
||||
{
|
||||
@ -765,6 +766,86 @@ class LocalStoreLogic extends Logic
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function countData($post, $user_id)
|
||||
{
|
||||
$where = [
|
||||
['lstore_id', '=', $post['lstore_id']],
|
||||
['user_id', '=', $user_id],
|
||||
['state', '=', 1]
|
||||
];
|
||||
|
||||
$model = new LocalGoodsOrder();
|
||||
|
||||
// 历史订单总和
|
||||
$history_total_amount = $model->where($where)->sum('goods_total_price');
|
||||
|
||||
// 本月业绩总和
|
||||
$current_month_start = date('Y-m-01 00:00:00'); // 当月开始日期
|
||||
$current_month_end = date('Y-m-t 23:59:59'); // 当月结束日期
|
||||
$current_month_total_amount = $model
|
||||
->where($where)
|
||||
->where([
|
||||
['dtime', '>=', $current_month_start],
|
||||
['dtime', '<=', $current_month_end]
|
||||
])->sum('goods_total_price');
|
||||
|
||||
// 上月业绩总和
|
||||
$last_month_start = date('Y-m-01 00:00:00', strtotime('-1 month')); // 上月开始日期
|
||||
$last_month_end = date('Y-m-t 23:59:59', strtotime('-1 month')); // 上月结束日期
|
||||
$last_month_total_amount = $model
|
||||
->where($where)
|
||||
->where([
|
||||
['dtime', '>=', $last_month_start],
|
||||
['dtime', '<=', $last_month_end]
|
||||
])->sum('goods_total_price');
|
||||
|
||||
// 当日营业额
|
||||
$current_day_start = date('Y-m-d 00:00:00');
|
||||
$current_day_end = date('Y-m-d 23:59:59');
|
||||
$current_day_total_amount = $model
|
||||
->where($where)
|
||||
->where([
|
||||
['dtime', '>=', $current_day_start],
|
||||
['dtime', '<=', $current_day_end]
|
||||
])->sum('goods_total_price');
|
||||
|
||||
// 统计当日数据: 总共支付交易笔数 report = 1(日报) report = 2(月报)
|
||||
$trade_where = $where;
|
||||
unset($trade_where[2]);
|
||||
|
||||
$count_trade = $model
|
||||
->where($post['report'] == 1 ? $trade_where : $where)
|
||||
->where([
|
||||
['dtime', '>=', $post['report'] == 1 ? $current_day_start : $current_month_start],
|
||||
['dtime', '<=', $post['report'] == 1 ? $current_day_end : $current_month_end]
|
||||
])->count();
|
||||
|
||||
// 支付成功交易笔数
|
||||
$success_trade = $model
|
||||
->where($post['report'] == 1 ? $trade_where : $where)
|
||||
->where([
|
||||
['dtime', '>=', $post['report'] == 1 ? $current_day_start : $current_month_start],
|
||||
['dtime', '<=', $post['report'] == 1 ? $current_day_end : $current_month_end]
|
||||
])->count();
|
||||
|
||||
// 单笔交易
|
||||
if ($post['report'] == 1) {
|
||||
$average_price = $success_trade > 0 ? $current_day_total_amount / $success_trade : 0;
|
||||
} elseif ($post['report'] == 2) {
|
||||
$average_price = $success_trade > 0 ? $current_month_total_amount / $success_trade : 0;
|
||||
}
|
||||
|
||||
return [
|
||||
'history_total_amount' => $history_total_amount,
|
||||
'current_month_total_amount' => $current_month_total_amount,
|
||||
'last_month_total_amount' => $last_month_total_amount,
|
||||
'current_day_total_amount' => $current_day_total_amount,
|
||||
'count_trade' => $count_trade,
|
||||
'success_trade' => $success_trade,
|
||||
'average_price' => $average_price
|
||||
];
|
||||
}
|
||||
|
||||
private static function crate_bind_menu($rule)
|
||||
{
|
||||
$menu = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user