UserCouponLists.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\coupon;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\coupon\UserCoupon;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\user\User;
  19. /**
  20. * UserCoupon列表
  21. * Class UserCouponLists
  22. * @package app\adminapi\lists
  23. */
  24. class UserCouponLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2025/05/28 11:42
  31. */
  32. public function setSearch(): array
  33. {
  34. return [
  35. '=' => ['user_id', 'coupon_id', 'coupon_target', 'voucher_status', 'voucher_count', 'amount', 'amount_require', 'begin_use', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'property_activity_id'],
  36. '%like%' => ['code','event_name'],
  37. ];
  38. }
  39. public function queryWhere()
  40. {
  41. $where = [];
  42. if (isset($this->params['mobile']) && !empty($this->params['mobile'])) {
  43. $user_ids = User::where([['mobile|real_name', 'like','%' .$this->params['mobile'] . '%']])->column('id')??[0];
  44. $where[] = ['user_id','in' ,$user_ids];
  45. }
  46. return $where;
  47. }
  48. /**
  49. * @notes 获取列表
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @author likeadmin
  55. * @date 2025/05/28 11:42
  56. */
  57. public function lists(): array
  58. {
  59. return UserCoupon::with(['user'])->where($this->searchWhere)->where($this->queryWhere())
  60. ->field(['*'])
  61. ->limit($this->limitOffset, $this->limitLength)
  62. ->order(['id' => 'desc'])
  63. ->select()
  64. ->toArray();
  65. }
  66. /**
  67. * @notes 获取数量
  68. * @return int
  69. * @author likeadmin
  70. * @date 2025/05/28 11:42
  71. */
  72. public function count(): int
  73. {
  74. return UserCoupon::where($this->searchWhere)->where($this->queryWhere())->count();
  75. }
  76. }