StoreCouponUserUserDao.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\activity\coupon;
  13. use app\dao\BaseDao;
  14. use app\model\activity\coupon\StoreCouponUser;
  15. use app\model\user\User;
  16. /**
  17. *
  18. * Class StoreCouponUserUserDao
  19. * @package app\dao\coupon
  20. */
  21. class StoreCouponUserUserDao extends BaseDao
  22. {
  23. protected $alias = '';
  24. protected $join_alis = '';
  25. /**
  26. * 设置模型
  27. * @return string
  28. */
  29. protected function setModel(): string
  30. {
  31. return StoreCouponUser::class;
  32. }
  33. /**
  34. * 连表模型
  35. * @return string
  36. */
  37. public function joinModel(): string
  38. {
  39. return User::class;
  40. }
  41. /**
  42. * 关联模型
  43. * @param string $alias
  44. * @param string $join_alias
  45. * @return \crmeb\basic\BaseModel
  46. */
  47. public function getModel(string $alias = 'c', string $join_alias = 'u', $join = 'left')
  48. {
  49. $this->alias = $alias;
  50. $this->join_alis = $join_alias;
  51. /** @var User $user */
  52. $user = app()->make($this->joinModel());
  53. $table = $user->getName();
  54. return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join)->alias($alias);
  55. }
  56. /**
  57. * 列表
  58. * @param array $where
  59. * @param int $page
  60. * @param int $limit
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function sysPage(array $where, int $page, int $limit)
  67. {
  68. return $this->searchWhere($where)->page($page, $limit)->order('id desc')->select()->toArray();
  69. }
  70. /**
  71. * 总数
  72. * @param array $where
  73. * @return int
  74. */
  75. public function sysCount(array $where)
  76. {
  77. return $this->searchWhere($where)->count();
  78. }
  79. /**
  80. * 筛选条件
  81. * @param array $where
  82. * @return \crmeb\basic\BaseModel
  83. */
  84. public function searchWhere(array $where = [])
  85. {
  86. return $this->getModel()
  87. ->when($where['nickname'] != '', function ($query) use ($where) {
  88. $query->where('u.nickname', 'like', '%' . $where['nickname'] . '%');
  89. })->when($where['status'] != '', function ($query) use ($where) {
  90. $query->where('c.status', $where['status']);
  91. })->when($where['coupon_title'] != '', function ($query) use ($where) {
  92. $query->where('c.coupon_title', 'like', '%' . $where['coupon_title'] . '%');
  93. })->field('c.*,u.nickname');
  94. }
  95. }