UserBillStoreOrderDao.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\dao\user;
  13. use app\dao\BaseDao;
  14. use app\model\order\StoreOrder;
  15. use app\model\user\UserBill;
  16. /**
  17. *
  18. * Class UserBillStoreOrderDao
  19. * @package app\dao\user
  20. */
  21. class UserBillStoreOrderDao extends BaseDao
  22. {
  23. protected $alias = '';
  24. protected $join_alis = '';
  25. /**
  26. * 设置模型
  27. * @return string
  28. */
  29. protected function setModel(): string
  30. {
  31. return UserBill::class;
  32. }
  33. public function joinModel(): string
  34. {
  35. return StoreOrder::class;
  36. }
  37. /**
  38. * 关联模型
  39. * @param string $alias
  40. * @param string $join_alias
  41. * @return \crmeb\basic\BaseModel
  42. */
  43. public function getModel(string $table = '', string $alias = 'b', string $join_alias = 'o', $join = 'left')
  44. {
  45. $this->alias = $alias;
  46. $this->join_alis = $join_alias;
  47. if (!$table) {
  48. /** @var StoreOrder $storeOrder */
  49. $storeOrder = app()->make($this->joinModel());
  50. $table = $storeOrder->getName();
  51. }
  52. return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.link_id = ' . $join_alias . '.id', $join)->alias($alias);
  53. }
  54. /**
  55. * 时间分组
  56. * @param array $where
  57. * @param array $whereOr
  58. * @param string $field
  59. * @param string $group
  60. * @param $page
  61. * @param $limit
  62. * @return mixed
  63. */
  64. public function getList(array $where, array $whereOr, array $times, string $field, $page, $limit)
  65. {
  66. return $this->getModel()->where($where)->where("FROM_UNIXTIME(b.add_time, '%Y-%m')", 'in', $times)
  67. ->where(function ($q) use ($whereOr) {
  68. $q->whereOr($whereOr);
  69. })
  70. ->with([
  71. 'user' => function ($query) {
  72. $query->field('uid,avatar,nickname')->bind(['avatar' => 'avatar', 'nickname' => 'nickname']);
  73. }])->field($field)->order('id desc')->page($page, $limit)->select()->toArray();
  74. }
  75. /**
  76. * 时间分组
  77. * @param array $where
  78. * @param array $whereOr
  79. * @param string $field
  80. * @param string $group
  81. * @param $page
  82. * @param $limit
  83. * @return mixed
  84. */
  85. public function getListByGroup(array $where, array $whereOr, string $field, string $group, $page, $limit)
  86. {
  87. return $this->getModel()->where($where)->where(function ($q) use ($whereOr) {
  88. $q->whereOr($whereOr);
  89. })->field($field)->order($group . ' desc')->group($group)->page($page, $limit)->select()->toArray();
  90. }
  91. /**
  92. * 时间分组
  93. * @param array $where
  94. * @param array $whereOr
  95. * @param string $field
  96. * @param string $group
  97. * @param $page
  98. * @param $limit
  99. * @return mixed
  100. */
  101. public function getListCount(array $where, array $whereOr)
  102. {
  103. return $this->getModel()->where($where)->where(function ($q) use ($whereOr) {
  104. $q->whereOr($whereOr);
  105. })->count('b.id');
  106. }
  107. }