CapitalFlowDao.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\system\statistics;
  12. use app\dao\BaseDao;
  13. use app\model\system\statistics\CapitalFlow;
  14. class CapitalFlowDao extends BaseDao
  15. {
  16. /**
  17. * 设置模型
  18. * @return string
  19. */
  20. protected function setModel(): string
  21. {
  22. return CapitalFlow::class;
  23. }
  24. /**
  25. * 资金流水
  26. * @param $where
  27. * @param int $page
  28. * @param int $limit
  29. * @return array
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function getList($where, $page = 0, $limit = 0)
  35. {
  36. return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
  37. $query->page($page, $limit);
  38. })->order('id desc')->select()->toArray();
  39. }
  40. /**
  41. * 账单记录
  42. * @param $where
  43. * @param int $page
  44. * @param int $limit
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function getRecordList($where, $page = 0, $limit = 0)
  51. {
  52. $model = $this->search($where)
  53. ->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  54. $timeUnix = '%d';
  55. switch ($where['type']) {
  56. case "day" :
  57. $timeUnix = "%d";
  58. break;
  59. case "week" :
  60. $timeUnix = "%u";
  61. break;
  62. case "month" :
  63. $timeUnix = "%m";
  64. break;
  65. }
  66. $query->field("FROM_UNIXTIME(add_time,'$timeUnix') as day,sum(if(price >= 0,price,0)) as income_price,sum(if(price < 0,price,0)) as exp_price,add_time,group_concat(id) as ids");
  67. $query->group("FROM_UNIXTIME(add_time, '$timeUnix')");
  68. });
  69. $count = $model->count();
  70. $list = $model->when($page && $limit, function ($query) use ($page, $limit) {
  71. $query->page($page, $limit);
  72. })->order('add_time desc')->select()->toArray();
  73. return compact('list', 'count');
  74. }
  75. }