Stats.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\agent\model\finance;
  3. use app\common\model\BaseModel;
  4. use think\Collection;
  5. use think\Model;
  6. class Stats extends BaseModel
  7. {
  8. public function getMonthTime($month): array
  9. {
  10. //
  11. $firstday = date('Y-m-01', strtotime(date('Y') . '-' . $month . '-1'));
  12. $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
  13. return array($firstday,$lastday);
  14. }
  15. /**
  16. * @desc desc
  17. * @param Model $model
  18. * @param $columnField
  19. * @param $columnKey
  20. * @param array $where
  21. * @param array|string $with
  22. * @return array
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. * @author weichuanbao<654745815@qq.com>
  27. * @date 2021/12/10 0010
  28. */
  29. public function getStats(Model $model, $columnField, $columnKey, $where = [], $with = '')
  30. {
  31. $map = array_merge([], $where);
  32. $array = ['total','today','month','year'];
  33. $data = [];
  34. foreach ($array as $key => $item) {
  35. $app = $model->with($with)->where($map);
  36. if ($key) {
  37. $app->whereTime('created_at', $item);
  38. }
  39. $list = $app->select();
  40. foreach ($list as $index => $value) {
  41. if (!$value['paylog']) {
  42. unset($list[$index]);
  43. }
  44. }
  45. $data[$item] = array_column(Collection::make($list)->toArray(), $columnField, $columnKey);
  46. }
  47. return $data;
  48. }
  49. }