PropertyActivityLists.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\property;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\property\PropertyActivity;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\property\PropertyHead;
  19. /**
  20. * PropertyActivity列表
  21. * Class PropertyActivityLists
  22. * @package app\adminapi\lists
  23. */
  24. class PropertyActivityLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2024/11/21 15:04
  31. */
  32. public function setSearch(): array
  33. {
  34. return [
  35. '=' => ['property_head_id', 'activity_name', 'activity_start_time', 'activity_end_time','page_type'],
  36. ];
  37. }
  38. /**
  39. * 获取数据权限
  40. * $this->adminInfo['data_rules']
  41. * province city admin_id sale_group_id sale_id property_head_id
  42. */
  43. public function queryDataWhere(){
  44. $where = [];
  45. $data_rules = $this->adminInfo['data_rules'];
  46. if (isset($data_rules['province']) && !empty($data_rules['province'])) {
  47. $where[] = ['province','in' ,$data_rules['province']];
  48. }
  49. if (isset($data_rules['city']) && !empty($data_rules['city'])) {
  50. $where[] = ['city','in' ,$data_rules['city']];
  51. }
  52. if(!empty($where)){
  53. $head_ids = PropertyHead::where($where)->column('id')??[0];
  54. $where = [['property_head_id','in' ,$head_ids]];
  55. }
  56. return $where;
  57. }
  58. /**
  59. * @notes 获取列表
  60. * @return array
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @author likeadmin
  65. * @date 2024/11/21 15:04
  66. */
  67. public function lists(): array
  68. {
  69. return PropertyActivity::with(['propertyHeadInfo'])
  70. ->where($this->searchWhere)->where($this->queryDataWhere())
  71. ->field(['id', 'property_head_id', 'activity_name', 'activity_start_time', 'activity_end_time','block_data','coupon_data','url_page','page_type','images'])
  72. ->limit($this->limitOffset, $this->limitLength)
  73. ->order(['id' => 'desc'])
  74. ->select()
  75. ->toArray();
  76. }
  77. /**
  78. * @notes 获取数量
  79. * @return int
  80. * @author likeadmin
  81. * @date 2024/11/21 15:04
  82. */
  83. public function count(): int
  84. {
  85. return PropertyActivity::where($this->searchWhere)->where($this->queryDataWhere())->count();
  86. }
  87. }