98 lines
6.1 KiB
PHP
Executable File
98 lines
6.1 KiB
PHP
Executable File
<?php
|
|
namespace app\shopapi\logic;
|
|
use app\common\enum\coach\CoachEnum;
|
|
use app\common\enum\OrderEnum;
|
|
use app\common\enum\PayEnum;
|
|
use app\common\enum\shop\ShopEnum;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\coach\Coach;
|
|
use app\common\model\order\Order;
|
|
use app\common\model\shop\Shop;
|
|
use app\common\model\shop\ShopCoachApply;
|
|
use app\common\model\shop\ShopVisit;
|
|
|
|
class IndexLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
public function shopData(int $shopId)
|
|
{
|
|
$todayShopVisit = ShopVisit::where(['shop_id'=>$shopId])->whereDay('create_time')->sum('visit');
|
|
$yesterdayShopVisit = ShopVisit::where(['shop_id'=>$shopId])->whereDay('create_time','yesterday')->sum('visit');
|
|
$todayOrderNum = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time')->count();
|
|
$yesterdayOrderNum = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time','yesterday')->count();
|
|
$todayOrderIncome = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time')->sum('total_amount');
|
|
$yesterdayOrderIncome = Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->whereDay('create_time','yesterday')->sum('total_amount');
|
|
// 计算浏览量的变化
|
|
$viewChange =$todayShopVisit - $yesterdayShopVisit;
|
|
// 计算百分比变化
|
|
if ($yesterdayShopVisit > 0) {
|
|
$shopVisitPercentChange = round(($viewChange / $yesterdayShopVisit) * 100,2);
|
|
} else {
|
|
$shopVisitPercentChange = $viewChange* 100;
|
|
}
|
|
0 == $shopVisitPercentChange && $shopVisitPercentChange = intval($shopVisitPercentChange);
|
|
$shopVisitPercentChange > 100 && $shopVisitPercentChange = 100;
|
|
// 计算订单数量的变化
|
|
$viewChange =$todayOrderNum - $yesterdayOrderNum;
|
|
// 计算百分比变化
|
|
if ($yesterdayOrderNum > 0) {
|
|
$orderNumChange = round(($viewChange / $yesterdayOrderNum) * 100,2);
|
|
} else {
|
|
$orderNumChange = $viewChange* 100;
|
|
}
|
|
0 == $orderNumChange && $orderNumChange = intval($orderNumChange);
|
|
$orderNumChange > 100 && $orderNumChange = 100;
|
|
// 计算订单数量的变化
|
|
$viewChange = $todayOrderIncome - $yesterdayOrderIncome;
|
|
// 计算百分比变化
|
|
if ($yesterdayOrderIncome > 0) {
|
|
$orderIncomeChange = round(($viewChange / $yesterdayOrderIncome) * 100,2);
|
|
} else {
|
|
$orderIncomeChange = $viewChange* 100;
|
|
}
|
|
0 == $orderIncomeChange && $orderIncomeChange = intval($orderIncomeChange);
|
|
$orderIncomeChange > 100 && $orderIncomeChange = 100;
|
|
$todayDate = date('Y-m-d',time());
|
|
//今天的时间戳
|
|
$todayStart = strtotime($todayDate);
|
|
$todayEnd = strtotime($todayDate . ' 23:59:59');
|
|
//明天的时间戳
|
|
$tomorrowStart = strtotime('+1 day',$todayStart);
|
|
$tomorrowEnd = strtotime('+1 day',$todayEnd);
|
|
//后天的时间戳
|
|
$dayAfterTomorrowStart = strtotime('+2 day',$todayStart);
|
|
$dayAfterTomorrowEnd = strtotime('+2 day',$todayEnd);
|
|
|
|
return [
|
|
'shop_name' => Shop::where(['id'=>$shopId])->value('name'),
|
|
'shop_data' => [
|
|
'shop_visit' => $todayShopVisit,
|
|
'visit_compare' => $shopVisitPercentChange.'%',
|
|
'order_num' => $todayOrderNum,
|
|
'order_num_compare' => $orderNumChange.'%',
|
|
'order_income' => $todayOrderIncome,
|
|
'order_income_compare' => $orderIncomeChange.'%',
|
|
],
|
|
'wait_order_data' => [
|
|
'today_order_num' => Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_PAY)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->whereDay('create_time','today')->count(),
|
|
'tomorrow_order_num' => Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_PAY)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->whereTime('appoint_time','between',[$tomorrowStart,$tomorrowEnd])->count(),
|
|
'dayafter_order_num' => Order::where(['shop_id'=>$shopId,'pay_status'=>PayEnum::ISPAID])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_PAY)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->whereTime('appoint_time','between',[$dayAfterTomorrowStart,$dayAfterTomorrowEnd])->count(),
|
|
],
|
|
'order_data' => [
|
|
'wait_server_num' => Order::where(['shop_id'=>$shopId])->where('order_status','>',OrderEnum::ORDER_STATUS_WAIT_RECEIVING)->where('order_status','<',OrderEnum::ORDER_STATUS_SERVER_FINISH)->count(),
|
|
'wait_take_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_WAIT_RECEIVING)->count(),
|
|
'depart_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_DEPART)->count(),
|
|
'arrive_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_ARRIVE)->count(),
|
|
'start_server_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_START_SERVER)->count(),
|
|
'finish_server_num' => Order::where(['shop_id'=>$shopId])->where('order_status','=',OrderEnum::ORDER_STATUS_SERVER_FINISH)->count(),
|
|
],
|
|
'coach_data' => [
|
|
'wait_audtit_num' => ShopCoachApply::where(['shop_id'=>$shopId,'audit_status'=>ShopEnum::AUDIT_STATUS_WAIT])->count(),
|
|
'online_coach_num' => Coach::where(['shop_id'=>$shopId,'audit_status'=>CoachEnum::AUDIT_STATUS_PASS,'work_status'=>CoachEnum::WORK_STATUS_ONLINE])->count(),
|
|
'downline_coach_num' => Coach::where(['shop_id'=>$shopId,'audit_status'=>CoachEnum::AUDIT_STATUS_PASS,'work_status'=>CoachEnum::WORK_STATUS_DOWNLINE])->count(),
|
|
],
|
|
|
|
];
|
|
}
|
|
} |