StoreUserDao.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\store;
  12. use app\dao\BaseDao;
  13. use app\model\store\StoreUser;
  14. /**
  15. * 门店用户
  16. * Class StoreUserDao
  17. * @package app\dao\store
  18. */
  19. class StoreUserDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return StoreUser::class;
  28. }
  29. /**
  30. * 获取用户列表
  31. * @param array $where
  32. * @param string $field
  33. * @param array $with
  34. * @param int $page
  35. * @param int $limit
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0): array
  42. {
  43. return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
  44. $query->with(['label']);
  45. })->when($page && $limit, function ($query) use ($page, $limit) {
  46. $query->page($page, $limit);
  47. })->select()->toArray();
  48. }
  49. /**
  50. * 获取一段时间内新增人数
  51. * @param array $where
  52. * @param array $time
  53. * @param string $timeType
  54. * @param string $countField
  55. * @param string $sumField
  56. * @param string $groupField
  57. * @return mixed
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function userTimeList(array $where, array $time, string $timeType = "week", string $countField = '*', string $sumField = 'pay_price', string $groupField = 'add_time')
  63. {
  64. return $this->getModel()->where($where)
  65. ->where($groupField, 'between time', $time)
  66. ->when($timeType, function ($query) use ($timeType, $countField, $sumField, $groupField) {
  67. switch ($timeType) {
  68. case "hour":
  69. $timeUnix = "%H";
  70. break;
  71. case "week" :
  72. $timeUnix = "%w";
  73. break;
  74. case "month" :
  75. $timeUnix = "%d";
  76. break;
  77. case "weekly" :
  78. $timeUnix = "%W";
  79. break;
  80. case "year" :
  81. $timeUnix = "%Y-%m";
  82. break;
  83. default:
  84. $timeUnix = "%m-%d";
  85. break;
  86. }
  87. $query->field("FROM_UNIXTIME(`" . $groupField . "`,'$timeUnix') as day,count(" . $countField . ") as count");
  88. $query->group('day');
  89. })->order('add_time asc')->select()->toArray();
  90. }
  91. }