2024-09-29 16:44:06 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace admin\controllers\base;
|
|
|
|
|
|
|
|
|
|
|
|
use admin\components\BaseAdminController;
|
|
|
|
|
|
use common\models\ChargeCashPayRecord;
|
|
|
|
|
|
use common\models\Ledger;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-module 分账
|
|
|
|
|
|
*/
|
|
|
|
|
|
class ChargeCashController extends BaseAdminController
|
|
|
|
|
|
{
|
|
|
|
|
|
public function actionList()
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO 待完善
|
|
|
|
|
|
$params = \Yii::$app->request->get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query = ChargeCashPayRecord::find();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($params['status'])) {
|
|
|
|
|
|
$query->where(['status' => $params['status']]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($params['store_id'])) {
|
|
|
|
|
|
$query->andWhere(['store_id' => $params['store_id']]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if (!empty($params['start_time']) && !empty($params['end_time'])) {
|
|
|
|
|
|
// // 确保 start_time 不大于 end_time
|
|
|
|
|
|
// if ($params['start_time'] <= $params['end_time']) {
|
|
|
|
|
|
// $query->andWhere(['between', 'created_at', $params['start_time'], $params['end_time']]);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// // 如果 start_time 大于 end_time,可以抛出异常或者记录错误
|
|
|
|
|
|
// throw new \InvalidArgumentException("Start time must be before end time.");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } elseif (!empty($params['start_time'])) {
|
|
|
|
|
|
// // 只有开始时间的情况下,查询 created_at 大于等于 start_time 的数据
|
|
|
|
|
|
// $query->andWhere(['>=', 'created_at', $params['start_time']]);
|
|
|
|
|
|
// } elseif (!empty($params['end_time'])) {
|
|
|
|
|
|
// // 只有结束时间的情况下,查询 created_at 小于等于 end_time 的数据
|
|
|
|
|
|
// $query->andWhere(['<=', 'created_at', $params['end_time']]);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query->with(['store'])->orderBy(['id' => SORT_DESC]);
|
|
|
|
|
|
$this->field = [
|
|
|
|
|
|
ChargeCashPayRecord::class => [
|
|
|
|
|
|
'id',
|
|
|
|
|
|
'store_id',
|
|
|
|
|
|
'order_no',
|
|
|
|
|
|
'charge_cash',
|
|
|
|
|
|
'type',
|
|
|
|
|
|
'status',
|
|
|
|
|
|
'store',
|
|
|
|
|
|
'created_at' => function ($le) {
|
|
|
|
|
|
return date('Y-m-d H:i:s', $le->created_at);
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($query, $params);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function actionCount()
|
|
|
|
|
|
{
|
2024-09-30 14:25:26 +08:00
|
|
|
|
$query = ChargeCashPayRecord::find();
|
|
|
|
|
|
$list = $query->where(['status' => 2])->all();
|
2024-09-29 16:44:06 +08:00
|
|
|
|
|
2024-09-30 14:25:26 +08:00
|
|
|
|
$today = 0; // 今日
|
|
|
|
|
|
$yesterday = 0; // 昨天
|
|
|
|
|
|
$week = 0; // 本周
|
|
|
|
|
|
$month = 0; // 本月
|
|
|
|
|
|
$total = 0;
|
|
|
|
|
|
foreach ($list as $item) {
|
|
|
|
|
|
if ($item->updated_at >= strtotime(date('Y-m-d'))) {
|
|
|
|
|
|
$today = bcadd($today, $item->charge_cash, 2);
|
|
|
|
|
|
$total = bcadd($total, $item->charge_cash, 2);
|
|
|
|
|
|
$week = bcadd($week, $item->charge_cash, 2);
|
|
|
|
|
|
$month = bcadd($month, $item->charge_cash, 2);
|
|
|
|
|
|
$yesterday = bcadd($yesterday, $item->charge_cash, 2);
|
|
|
|
|
|
} elseif ($item->updated_at >= strtotime(date('Y-m-d', strtotime('-1 day'))) && $item->updated_at < strtotime(date('Y-m-d'))) {
|
|
|
|
|
|
$yesterday = bcadd($yesterday, $item->charge_cash, 2);
|
|
|
|
|
|
$total = bcadd($total, $item->charge_cash, 2);
|
|
|
|
|
|
$week = bcadd($week, $item->charge_cash, 2);
|
|
|
|
|
|
$month = bcadd($month, $item->charge_cash, 2);
|
|
|
|
|
|
} elseif ($item->updated_at >= strtotime(date('Y-m-d', strtotime('-7 day'))) && $item->updated_at < strtotime(date('Y-m-d', strtotime('-1 day')))) {
|
|
|
|
|
|
$week = bcadd($week, $item->charge_cash, 2);
|
|
|
|
|
|
$total = bcadd($total, $item->charge_cash, 2);
|
|
|
|
|
|
$month = bcadd($month, $item->charge_cash, 2);
|
|
|
|
|
|
} elseif ($item->updated_at >= strtotime(date('Y-m-01')) && $item->updated_at < strtotime(date('Y-m-d', strtotime('-7 day')))) {
|
|
|
|
|
|
$month = bcadd($month, $item->charge_cash, 2);
|
|
|
|
|
|
$total = bcadd($total, $item->charge_cash, 2);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$total = bcadd($total, $item->charge_cash, 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return [
|
|
|
|
|
|
'today' => $today,
|
|
|
|
|
|
'yesterday' => $yesterday,
|
|
|
|
|
|
'week' => $week,
|
|
|
|
|
|
'month' => $month,
|
|
|
|
|
|
'total' => $total
|
|
|
|
|
|
];
|
2024-09-29 16:44:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|