HomeSpecialLists.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\api\lists;
  3. use app\adminapi\lists\BaseAdminDataLists;
  4. use app\common\model\goods\Goods;
  5. use app\common\model\home_service\HomeSpecial;
  6. use app\common\lists\ListsSearchInterface;
  7. /**
  8. * HomeSpecial列表
  9. * Class HomeSpecialLists
  10. * @package app\api\listshome_service
  11. */
  12. class HomeSpecialLists extends BaseApiDataLists implements ListsSearchInterface
  13. {
  14. /**
  15. * @notes 设置搜索条件
  16. * @return \string[][]
  17. * @author likeadmin
  18. * @date 2024/11/18 10:05
  19. */
  20. public function setSearch(): array
  21. {
  22. return [
  23. '=' => ['special_type'],
  24. ];
  25. }
  26. public function queryWhere()
  27. {
  28. $where = [];
  29. if (!empty($this->params['id'])) {
  30. if(empty($this->params['limit'])){
  31. $where[] = ['id','>=',$this->params['id']];
  32. }
  33. $where[] = ['cover_type','=',1];
  34. }
  35. return $where;
  36. }
  37. /**
  38. * @notes 获取列表
  39. * @return array
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @author likeadmin
  44. * @date 2024/11/18 10:05
  45. */
  46. public function lists(): array
  47. {
  48. return HomeSpecial::where($this->searchWhere)
  49. ->where($this->queryWhere())
  50. ->where('status',1)
  51. ->field(['id', 'special_type','special_way', 'title', 'cover_type', 'cover', 'user_head', 'user_nickname', 'vue_web', 'vue_param', 'view_num', 'tags', 'status', 'original_price' ,'present_price','goods_id'])
  52. ->limit($this->limitOffset, $this->limitLength)
  53. ->order(['id' => 'desc'])
  54. ->select()
  55. ->each(function($item){
  56. if($item->goods_id){
  57. $item->goods = Goods::where('id',$item->goods_id)->field('goods_banners,goods_name,service_total,service_fee')->findOrEmpty();
  58. }
  59. if($item->vue_web=='pages/preview/videoPre' || $item->vue_web=='pages/preview/imagePre' || $item->vue_web=='pages/preview/richView'){
  60. $item->vue_param = 'id='.$item->id;
  61. }
  62. })
  63. ->toArray();
  64. }
  65. /**
  66. * @notes 获取数量
  67. * @return int
  68. * @author likeadmin
  69. * @date 2024/11/18 10:05
  70. */
  71. public function count(): int
  72. {
  73. return HomeSpecial::where($this->searchWhere)->where($this->queryWhere())->count();
  74. }
  75. }