GroupActivityLists.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\group_activity;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\group_activity\GroupActivity;
  17. use app\common\lists\ListsSearchInterface;
  18. /**
  19. * 拼团活动列表
  20. * Class GroupActivityLists
  21. * @package app\adminapi\listsgroup_activity
  22. */
  23. class GroupActivityLists extends BaseAdminDataLists implements ListsSearchInterface
  24. {
  25. /**
  26. * @notes 设置搜索条件
  27. * @return \string[][]
  28. * @author likeadmin
  29. * @date 2025/03/13 10:31
  30. */
  31. public function setSearch(): array
  32. {
  33. return [
  34. '=' => ['type', 'is_simulate_form'],
  35. '%like%' => ['title'],
  36. ];
  37. }
  38. public function queryWhere(){
  39. $where = [];
  40. if(!empty($this->params['area'])){
  41. $where[] = ['area', 'like', '%'.$this->params['area'].'%'];
  42. }
  43. return $where;
  44. }
  45. /**
  46. * @notes 获取拼团活动列表
  47. * @return array
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @author likeadmin
  52. * @date 2025/03/13 10:31
  53. */
  54. public function lists(): array
  55. {
  56. $list = GroupActivity::where($this->searchWhere)
  57. ->where($this->queryWhere())
  58. ->field(['id', 'title', 'image','equity_id','origin_price','price','start_time', 'end_time', 'participant_num', 'type', 'form_time_limit', 'is_simulate_form', 'simulate_num','area'])
  59. ->limit($this->limitOffset, $this->limitLength)
  60. ->order(['id' => 'desc'])
  61. ->select()
  62. ->toArray();
  63. foreach ($list as $key => &$item) {
  64. $item['price'] = $item['price'] ? explode(',', $item['price']) : [];
  65. $item['participant_num'] = $item['participant_num'] ? explode(',', $item['participant_num']) : [];
  66. $item['simulate_num'] = $item['simulate_num'] ? explode(',', $item['simulate_num']) : [];
  67. $item['area'] = $item['area'] ? explode(',', $item['area']) : [];
  68. }
  69. return $list;
  70. }
  71. /**
  72. * @notes 获取拼团活动数量
  73. * @return int
  74. * @author likeadmin
  75. * @date 2025/03/13 10:31
  76. */
  77. public function count(): int
  78. {
  79. return GroupActivity::where($this->searchWhere)->where($this->queryWhere())->count();
  80. }
  81. }