StoreCouponUserUserDao.php 3.1 KB

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