HomeSpecialLists.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  27. * @notes 获取列表
  28. * @return array
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @author likeadmin
  33. * @date 2024/11/18 10:05
  34. */
  35. public function lists(): array
  36. {
  37. return HomeSpecial::where($this->searchWhere)
  38. ->where('status',1)
  39. ->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'])
  40. ->limit($this->limitOffset, $this->limitLength)
  41. ->order(['id' => 'desc'])
  42. ->select()
  43. ->each(function($item){
  44. if($item->goods_id){
  45. $item->goods = Goods::where('id',$item->goods_id)->field('goods_banners,goods_name,service_total,service_fee')->findOrEmpty();
  46. }
  47. })
  48. ->toArray();
  49. }
  50. /**
  51. * @notes 获取数量
  52. * @return int
  53. * @author likeadmin
  54. * @date 2024/11/18 10:05
  55. */
  56. public function count(): int
  57. {
  58. return HomeSpecial::where($this->searchWhere)->count();
  59. }
  60. }