GroupActivityLists.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  69. }
  70. return $list;
  71. }
  72. /**
  73. * @notes 获取拼团活动数量
  74. * @return int
  75. * @author likeadmin
  76. * @date 2025/03/13 10:31
  77. */
  78. public function count(): int
  79. {
  80. return GroupActivity::where($this->searchWhere)->where($this->queryWhere())->count();
  81. }
  82. }