| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\agent\model\finance;
- use app\common\model\BaseModel;
- use think\Collection;
- use think\Model;
- class Stats extends BaseModel
- {
- public function getMonthTime($month): array
- {
- //
- $firstday = date('Y-m-01', strtotime(date('Y') . '-' . $month . '-1'));
- $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
- return array($firstday,$lastday);
- }
- /**
- * @desc desc
- * @param Model $model
- * @param $columnField
- * @param $columnKey
- * @param array $where
- * @param array|string $with
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @author weichuanbao<654745815@qq.com>
- * @date 2021/12/10 0010
- */
- public function getStats(Model $model, $columnField, $columnKey, $where = [], $with = '')
- {
- $map = array_merge([], $where);
- $array = ['total','today','month','year'];
- $data = [];
- foreach ($array as $key => $item) {
- $app = $model->with($with)->where($map);
- if ($key) {
- $app->whereTime('created_at', $item);
- }
- $list = $app->select();
- foreach ($list as $index => $value) {
- if (!$value['paylog']) {
- unset($list[$index]);
- }
- }
- $data[$item] = array_column(Collection::make($list)->toArray(), $columnField, $columnKey);
- }
- return $data;
- }
- }
|