123 lines
4.3 KiB
PHP
123 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace admin\controllers\base;
|
|
|
|
use admin\components\BaseAdminController;
|
|
use common\models\oldDb\ChargeCashPayRecord;
|
|
|
|
/**
|
|
* @doc-module 待付
|
|
*/
|
|
class ChargeCashController extends BaseAdminController
|
|
{
|
|
/**
|
|
* 待付列表
|
|
*
|
|
* @return \yii\data\ActiveDataProvider
|
|
*/
|
|
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'])) {
|
|
$query->andWhere(['between', 'created_at', strtotime($params['start_time']. ' 00:00:00'), strtotime($params['end_time']. ' 23:59:59')]);
|
|
}
|
|
|
|
|
|
$query->with(['store', 'supplier'])->orderBy(['id' => SORT_DESC]);
|
|
$this->field = [
|
|
ChargeCashPayRecord::class => [
|
|
'id',
|
|
'store_id',
|
|
'order_no',
|
|
'charge_cash',
|
|
'type',
|
|
'status',
|
|
'store' => function ($query) {
|
|
return empty($query->store)? $query->supplier: $query->store;
|
|
},
|
|
'created_at' => function ($le) {
|
|
return date('Y-m-d H:i:s', $le->created_at);
|
|
}
|
|
],
|
|
];
|
|
return $this->create($query, $params);
|
|
}
|
|
|
|
/**
|
|
* 统计代付金额
|
|
*
|
|
* @return array
|
|
*/
|
|
public function actionCount()
|
|
{
|
|
// 查询充值提现记录
|
|
$query = ChargeCashPayRecord::find();
|
|
// 筛选状态为2的记录
|
|
$list = $query->where(['status' => 2])->all();
|
|
|
|
// 初始化各时间段的充值提现金额
|
|
$today = 0; // 今日
|
|
$yesterday = 0; // 昨天
|
|
$week = 0; // 本周
|
|
$month = 0; // 本月
|
|
$total = 0; // 总计
|
|
// 遍历记录,按时间累加各时间段的金额
|
|
foreach ($list as $item) {
|
|
// 今日的记录
|
|
if ($item->updated_at >= strtotime(date('Y-m-d'))) {
|
|
$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);
|
|
$yesterday = bcadd($yesterday, $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);
|
|
$yesterday = bcadd($yesterday, $item->charge_cash, 2);
|
|
// 本月的记录
|
|
} elseif ($item->updated_at >= strtotime(date('Y-m-01'))) {
|
|
$month = bcadd($month, $item->charge_cash, 2);
|
|
$total = bcadd($total, $item->charge_cash, 2);
|
|
$yesterday = bcadd($yesterday, $item->charge_cash, 2);
|
|
// 本年的记录
|
|
} elseif ($item->updated_at >= strtotime(date('Y-01-01'))) {
|
|
$yesterday = bcadd($yesterday, $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
|
|
];
|
|
}
|
|
} |