HomeSpecialLists.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(['weight' => '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. if($item->vue_web=='pages/web_view/index'){
  63. $token = !empty($this->userInfo->token)?$this->userInfo->token:'';
  64. $item->vue_param = rawurlencode('https://weixiu.kyjlkj.com/static/wxapp/H5/adver5/index.html?property_activity_id=2&token='.$token);
  65. }
  66. })
  67. ->toArray();
  68. }
  69. /**
  70. * @notes 获取数量
  71. * @return int
  72. * @author likeadmin
  73. * @date 2024/11/18 10:05
  74. */
  75. public function count(): int
  76. {
  77. return HomeSpecial::where($this->searchWhere)->where($this->queryWhere())->count();
  78. }
  79. }