订单相关数据查询
This commit is contained in:
parent
f2d777d5e3
commit
6280a3e6b6
@ -105,7 +105,7 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
$extra['transaction_id'] = time();
|
$extra['transaction_id'] = time();
|
||||||
}
|
}
|
||||||
$user = User::where('id', $order['uid'])->find();
|
$user = User::where('id', $order['uid'])->find();
|
||||||
if ($order->pay_type == 9) {
|
if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) {//收银台支付
|
||||||
$order->status = 2;
|
$order->status = 2;
|
||||||
} else {
|
} else {
|
||||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||||
@ -275,6 +275,10 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
$amount = min($deposit, $frozen);
|
$amount = min($deposit, $frozen);
|
||||||
$financeLogic->in($transaction_id, $amount, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id']);
|
$financeLogic->in($transaction_id, $amount, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id']);
|
||||||
}
|
}
|
||||||
|
//入商户帐
|
||||||
|
if($deposit <= 0 && $frozen > 0){
|
||||||
|
SystemStore::where('id',$order['store_id'])->inc('store_money',$frozen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$financeLogic->save();
|
$financeLogic->save();
|
||||||
}
|
}
|
||||||
|
@ -142,4 +142,22 @@ class WorkbenchController extends BaseAdminController
|
|||||||
return $workbench->get_product_ranking();
|
return $workbench->get_product_ranking();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[
|
||||||
|
ApiDoc\Title('收银台数据统计'),
|
||||||
|
ApiDoc\url('/store/workbench/business_statistics'),
|
||||||
|
ApiDoc\Method('GET'),
|
||||||
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Author('中国队长'),
|
||||||
|
ApiDoc\Query(),
|
||||||
|
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||||
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
|
]
|
||||||
|
public function business_statistics()
|
||||||
|
{
|
||||||
|
$params = $this->request->get();
|
||||||
|
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||||
|
$result = WorkbenchLogic::revenueStatistics($params);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,19 @@
|
|||||||
namespace app\store\logic;
|
namespace app\store\logic;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\enum\OrderEnum;
|
||||||
use app\common\enum\PayEnum;
|
use app\common\enum\PayEnum;
|
||||||
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\logic\store_order\StoreOrderLogic;
|
use app\common\logic\store_order\StoreOrderLogic;
|
||||||
|
use app\common\logic\StoreFinanceFlowLogic;
|
||||||
use app\common\model\order\Cart;
|
use app\common\model\order\Cart;
|
||||||
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
|
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
|
||||||
|
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
use app\common\model\store_visit\StoreVisit;
|
use app\common\model\store_visit\StoreVisit;
|
||||||
|
use app\common\model\system_store\SystemStore;
|
||||||
use app\common\service\ConfigService;
|
use app\common\service\ConfigService;
|
||||||
use app\common\service\FileService;
|
use app\common\service\FileService;
|
||||||
|
|
||||||
@ -529,4 +534,161 @@ class WorkbenchLogic extends BaseLogic
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function revenueStatistics($params)
|
||||||
|
{
|
||||||
|
|
||||||
|
//当日营业额的统计 当日利润的统计 当日成本合集的统计 当日加到保证金的 当日的现金收银
|
||||||
|
$today = StoreOrder::where(['paid'=>YesNoEnum::YES,'store_id'=>$params['store_id']]);
|
||||||
|
$turnover_today = $today
|
||||||
|
->whereDay('create_time')
|
||||||
|
->sum('pay_price');
|
||||||
|
$profit_today = $today
|
||||||
|
->whereDay('create_time')
|
||||||
|
->sum('profit');
|
||||||
|
$cost_today = $today
|
||||||
|
->whereDay('create_time')
|
||||||
|
->sum('cost');
|
||||||
|
|
||||||
|
$deposit = StoreFinanceFlow::where(['store_id'=>$params['store_id']])
|
||||||
|
->where('financial_type',OrderEnum::ORDER_MARGIN);
|
||||||
|
$deposit_today =$deposit
|
||||||
|
->whereDay('create_time')
|
||||||
|
->sum('number');
|
||||||
|
|
||||||
|
$cash_today = StoreCashFinanceFlow::where('store_id',$params['store_id'])
|
||||||
|
->whereDay('create_time')
|
||||||
|
->where('status',YesNoEnum::YES)
|
||||||
|
->sum('receipts');
|
||||||
|
|
||||||
|
//总的营业额的统计 总的利润的统计 总的成本合集的统计 总的加到保证金的
|
||||||
|
$all = StoreOrder::where(['paid'=>YesNoEnum::YES,'store_id'=>$params['store_id']]);
|
||||||
|
$turnover_all = $all
|
||||||
|
->sum('pay_price');
|
||||||
|
$profit_all = $all
|
||||||
|
->sum('profit');
|
||||||
|
$cost_all = $all
|
||||||
|
->sum('cost');
|
||||||
|
$deposit_all = SystemStore::where('id',$params['store_id'])
|
||||||
|
->value('paid_deposit');
|
||||||
|
$cash_all = StoreCashFinanceFlow::where('store_id',$params['store_id'])
|
||||||
|
->where('status',YesNoEnum::YES)
|
||||||
|
->sum('receipts');
|
||||||
|
|
||||||
|
|
||||||
|
$time = self::getLastSevenDays();
|
||||||
|
$newArr = [];
|
||||||
|
foreach ($time as $value){
|
||||||
|
$data = self::dealSearch($params['store_id'],$value);
|
||||||
|
$newArr[$value] = $data;
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'today'=>[
|
||||||
|
'turnover_today'=>$turnover_today,
|
||||||
|
'profit_today'=>$profit_today,
|
||||||
|
'cost_today'=>$cost_today,
|
||||||
|
'deposit_today'=>$deposit_today,
|
||||||
|
'cash_today'=>$cash_today,
|
||||||
|
],
|
||||||
|
'all'=>[
|
||||||
|
'turnover_all'=>$turnover_all,
|
||||||
|
'profit_all'=>$profit_all,
|
||||||
|
'cost_all'=>$cost_all,
|
||||||
|
'deposit_all'=>$deposit_all,
|
||||||
|
'cash_all'=>$cash_all,
|
||||||
|
],
|
||||||
|
'time'=>$newArr
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
// 可以选时间 当日订单数 本月订单数 拆分线上和线下的方式 ---v.01
|
||||||
|
/* if($params['start_time'] && $params['end_time']){
|
||||||
|
$startTime = $params['start_time'];
|
||||||
|
$endTime = $params['end_time'];
|
||||||
|
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||||
|
}else{
|
||||||
|
$startTime = date('Y-m-d',time());
|
||||||
|
$endTime = date('Y-m-d', strtotime($startTime) + 86400);
|
||||||
|
}
|
||||||
|
|
||||||
|
//当日订单和当月订单
|
||||||
|
$base = StoreOrder::where('paid',YesNoEnum::YES);
|
||||||
|
$offline_order_today_num =$base
|
||||||
|
->whereIn('shipping_type',OrderEnum::OFFLINE)
|
||||||
|
->whereDay('create_time')
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$offline_order_today_month = $base
|
||||||
|
->whereIn('shipping_type',OrderEnum::OFFLINE)
|
||||||
|
->whereMonth('create_time')
|
||||||
|
->count();
|
||||||
|
//条码收银的-->微信和支付宝的没那个
|
||||||
|
|
||||||
|
//线下现金收银
|
||||||
|
whereIn('pay_type',[OrderEnum::CASHIER_ORDER_PAY,
|
||||||
|
OrderEnum::CASHIER_ORDER_ALI_PAY,OrderEnum::CASHIER_FACE_PAY])
|
||||||
|
$cash = StoreCashFinanceFlow::where('store_id',$params['store_id'])
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->where('status',YesNoEnum::YES);
|
||||||
|
$cash_count = $cash->count();
|
||||||
|
$cash_receipt = $cash->sum('receipts');*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getLastSevenDays()
|
||||||
|
{
|
||||||
|
$dates = [];
|
||||||
|
$today = new \DateTime(); // 获取当前日期
|
||||||
|
|
||||||
|
for ($i = 0; $i < 30; $i++) {
|
||||||
|
$date = clone $today; // 克隆当前日期对象,以避免修改原始对象
|
||||||
|
$date->modify("-$i day"); // 减去相应的天数
|
||||||
|
$dates[] = $date->format('Y-m-d'); // 格式化日期并添加到数组中
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dates;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function dealSearch($store_id,$startTime)
|
||||||
|
{
|
||||||
|
$endTime = date('Y-m-d', strtotime($startTime) + 86400);
|
||||||
|
//当日营业额的统计 当日利润的统计 当日成本合集的统计 当日加到保证金的 当日的现金收银
|
||||||
|
$today = StoreOrder::where(['paid'=>YesNoEnum::YES,'store_id'=>$store_id]);
|
||||||
|
$turnover_today = $today
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->sum('pay_price');
|
||||||
|
$profit_today = $today
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->sum('profit');
|
||||||
|
$cost_today = $today
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->sum('cost');
|
||||||
|
|
||||||
|
$deposit = StoreFinanceFlow::where(['store_id'=>$store_id])
|
||||||
|
->where('financial_type',OrderEnum::ORDER_MARGIN);
|
||||||
|
$deposit_today =$deposit
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->sum('number');
|
||||||
|
|
||||||
|
$cash_today = StoreCashFinanceFlow::where('store_id',$store_id)
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->where('status',YesNoEnum::YES)
|
||||||
|
->sum('receipts');
|
||||||
|
return [
|
||||||
|
'turnover_today'=>$turnover_today,
|
||||||
|
'profit_today'=>$profit_today,
|
||||||
|
'cost_today'=>$cost_today,
|
||||||
|
'deposit_today'=>$deposit_today,
|
||||||
|
'cash_today'=>$cash_today,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user