feat: 修改了WorkbenchLogic逻辑,优化了代码结构,统一了查询条件,并调整了部分方法的参数。
This commit is contained in:
parent
e25fe49941
commit
ccdbb687a5
@ -49,7 +49,7 @@ class WorkbenchController extends BaseAdminController
|
||||
{
|
||||
$params = $this->request->get();
|
||||
if(!isset($params['store_id']) ||$params['store_id']==''){
|
||||
$params['store_id'] =1;
|
||||
$params['store_id'] =0;
|
||||
}
|
||||
if(!isset($params['start_time']) ||$params['start_time']==''){
|
||||
$time=explode('-', $this->getDay(''));
|
||||
|
@ -306,9 +306,9 @@ class StoreOrderLogic extends BaseLogic
|
||||
* @param $extra
|
||||
* @return float|\think\db\Query
|
||||
*/
|
||||
public function storeOrderSumByDate($storeId, $start, $end, $extra = [], $field = 'pay_price')
|
||||
public function storeOrderSumByDate($start, $end, $extra = [], $field = 'pay_price')
|
||||
{
|
||||
return StoreOrder::where('store_id', $storeId)->where('paid', 1)->where($extra)->whereBetweenTime('pay_time', $start, $end)->sum($field);
|
||||
return StoreOrder::where($extra)->whereBetweenTime('pay_time', $start, $end)->sum($field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,30 +52,33 @@ class WorkbenchLogic extends BaseLogic
|
||||
$endTime = $params['end_time'];
|
||||
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||
$dateDiff = (new \DateTime($endTime))->diff(new \DateTime($startTime));
|
||||
|
||||
$where = ['paid' => 1];
|
||||
$cashFinanceWhere = [];
|
||||
$storeFinanceWhere = [];
|
||||
if ($params['store_id'] != 0) {
|
||||
$where['store_id'] = $params['store_id'];
|
||||
$cashFinanceWhere = ['store_id' => $params['store_id']];
|
||||
$storeFinanceWhere = ['store_id' => $params['store_id'],'financial_type'=>11,'financial_pm'=>0];
|
||||
}
|
||||
$orderLogic = new StoreOrderLogic();
|
||||
//订单总金额
|
||||
$data['order_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime);
|
||||
$data['order_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, $where);
|
||||
//余额支付总金额
|
||||
$data['balance_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['pay_type' => PayEnum::BALANCE_PAY]);
|
||||
$data['balance_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['pay_type' => PayEnum::BALANCE_PAY]));
|
||||
//线下收银总金额
|
||||
$data['cashier_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 3]);
|
||||
$data['cashier_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 3]));
|
||||
//现金收银总金额
|
||||
$data['cash_amount'] = StoreCashFinanceFlow::where('store_id', $params['store_id'])->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price');
|
||||
$data['cash_amount'] = StoreCashFinanceFlow::where($cashFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price');
|
||||
//核销订单金额
|
||||
$data['verify_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 2]);
|
||||
$data['verify_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, array_merge($where, ['shipping_type' => 2]));
|
||||
//门店收益金额
|
||||
$data['income_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, [], 'profit');
|
||||
$data['income_amount'] = $orderLogic->storeOrderSumByDate($startTime, $endTime, [], 'profit');
|
||||
//门店收款金额
|
||||
$data['receipt_amount'] = UserRecharge::where([
|
||||
'store_id'=>$params['store_id'],
|
||||
'paid'=>YesNoEnum::YES
|
||||
])->sum('price');
|
||||
$data['receipt_amount'] = UserRecharge::where($where)->sum('price');
|
||||
|
||||
$data['deposit_amount'] = StoreFinanceFlow::where('store_id', $params['store_id'])->where('financial_type',11)->where('financial_pm',0)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number');
|
||||
$data['deposit_amount'] = StoreFinanceFlow::where($storeFinanceWhere)->whereBetweenTime('create_time', $startTime, $endTime)->sum('number');
|
||||
//门店成交用户数
|
||||
$data['user_number'] = StoreOrder::where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
$data['user_number'] = StoreOrder::where($where)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group('uid')
|
||||
->count();
|
||||
@ -96,8 +99,7 @@ class WorkbenchLogic extends BaseLogic
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$group = 'MONTH(pay_time)';
|
||||
$i = 0;
|
||||
$month = 0;
|
||||
@ -117,15 +119,13 @@ class WorkbenchLogic extends BaseLogic
|
||||
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
|
||||
}
|
||||
$orderList = StoreOrder::field($field)
|
||||
->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->where($where)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group($group)
|
||||
->select()
|
||||
->toArray();
|
||||
$userList = StoreOrder::field($field . ',count(uid) as user_num')
|
||||
->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->where($where)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group($group . ',uid')
|
||||
->select()
|
||||
@ -155,8 +155,7 @@ class WorkbenchLogic extends BaseLogic
|
||||
'user_number' => array_values($userListTmp)
|
||||
]
|
||||
];
|
||||
$data['order_list'] = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
$data['order_list'] = StoreOrder::with('user')->where($where)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->order('pay_time', 'desc')
|
||||
->limit(10)
|
||||
@ -590,8 +589,7 @@ class WorkbenchLogic extends BaseLogic
|
||||
->sum('receivable');
|
||||
if (isset($params['month']) && $params['month']) {
|
||||
$all = StoreOrder::where(['paid' => YesNoEnum::YES, 'store_id' => $params['store_id']])
|
||||
->whereMonth('create_time', $params['month'])
|
||||
;
|
||||
->whereMonth('create_time', $params['month']);
|
||||
$deposit_all = SystemStore::where('id', $params['store_id'])
|
||||
->whereMonth('create_time', $params['month'])
|
||||
->value('paid_deposit');
|
||||
@ -605,8 +603,7 @@ class WorkbenchLogic extends BaseLogic
|
||||
$profit_all = $all
|
||||
->sum('profit');
|
||||
//消耗余额 V2.0
|
||||
$cost_all = CapitalFlow::
|
||||
where(['category'=>'user_order_balance_pay','store_id'=>$params['store_id']])
|
||||
$cost_all = CapitalFlow::where(['category' => 'user_order_balance_pay', 'store_id' => $params['store_id']])
|
||||
->sum('amount');
|
||||
|
||||
$time = self::getLastSevenDays();
|
||||
@ -665,7 +662,6 @@ class WorkbenchLogic extends BaseLogic
|
||||
->where('status',YesNoEnum::YES);
|
||||
$cash_count = $cash->count();
|
||||
$cash_receipt = $cash->sum('receipts');*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -716,7 +712,6 @@ class WorkbenchLogic extends BaseLogic
|
||||
'deposit_today' => $deposit_today,
|
||||
'cash_today' => $cash_today,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public static function rechargeData($params)
|
||||
@ -775,7 +770,6 @@ class WorkbenchLogic extends BaseLogic
|
||||
]
|
||||
];
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -878,6 +872,4 @@ class WorkbenchLogic extends BaseLogic
|
||||
}
|
||||
return array_merge($list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user