Index.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: TABLE ME
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-25 17:23
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\api\controller\v1;
  13. use app\BaseController;
  14. use app\model\api\SiteProduct;
  15. use app\model\system\News;
  16. use app\Request;
  17. use library\services\UtilService;
  18. use library\utils\AdvertUtils;
  19. class Index extends BaseController
  20. {
  21. /**
  22. * 获取首页数据
  23. */
  24. public function getIndex(Request $request) {
  25. $sassid = $request->site['sassid'];
  26. $siteProduct = new SiteProduct;
  27. $siteProduct->setSass($sassid);
  28. $banner = (new AdvertUtils($sassid))->getData('62');
  29. $data['banner'] = $banner;
  30. $data['sort_product'] = $siteProduct->SortList();//排行榜
  31. foreach ($data['sort_product'] as $k=>$v) {
  32. $imgAr = explode(',',$v['img']);
  33. $data['sort_product'][$k]['img'] = empty($imgAr) ? '' : $imgAr[0];
  34. }
  35. $newList = $siteProduct->NewsList();//新品上市
  36. foreach ($newList as $k=>$v) {
  37. $imgAr = explode(',',$v['img']);
  38. $newList[$k]['img'] = empty($imgAr) ? '' : $imgAr[0];
  39. }
  40. shuffle($newList);
  41. $data['new_product'] = $newList;
  42. shuffle($newList);
  43. $data['hot_product'] = $newList;
  44. return app('json')->success($data);
  45. }
  46. /**
  47. * 获取产品列表数据
  48. * @param Request $request
  49. */
  50. public function proList(Request $request){
  51. $post = UtilService::getMore([
  52. ['page',1],
  53. ['warehouse',0],
  54. ['countType','0'],
  55. ['type','all'],
  56. ['pageSize',20]
  57. ],$request);
  58. $pageSize = $post['pageSize'];
  59. $sassid = $request->site['sassid'];
  60. $siteProduct = new SiteProduct;
  61. $siteProduct->setSass($sassid);
  62. list($pageCount,$data) = $siteProduct->getList($post['page'],$post,$pageSize);
  63. foreach ($data as $k=>$v) {
  64. $imgAr = explode(',',$v['img']);
  65. $data[$k]['img'] = empty($imgAr) ? '' : $imgAr[0];
  66. }
  67. return app('json')->success([
  68. 'list' => $data,
  69. 'pageCount' => $pageCount,
  70. 'pageSize' => $pageSize,
  71. 'page' => $post['page']
  72. ]);
  73. }
  74. /**
  75. * 产品详情数据
  76. * @param Request $request
  77. * @return mixed
  78. */
  79. public function proItem(Request $request) {
  80. $post = UtilService::getMore([['id',0,'empty','请输入产品ID']],$request);
  81. $sassid = $request->site['sassid'];
  82. $siteProduct = new SiteProduct;
  83. $siteProduct->setSass($sassid);
  84. $data = $siteProduct->getItem($post['id']);
  85. if(empty($data)) {
  86. return app('json')->fail("找不到产品数据");
  87. } else {
  88. return app('json')->success($data);
  89. }
  90. }
  91. /**
  92. * 随机产品
  93. */
  94. public function proRand(Request $request) {
  95. $sassid = $request->site['sassid'];
  96. $siteProduct = new SiteProduct;
  97. $siteProduct->setSass($sassid);
  98. $data = $siteProduct->getRand(5);
  99. return app('json')->success($data);
  100. }
  101. /**
  102. * 新闻数据
  103. * @param Request $request
  104. */
  105. public function news(Request $request) {
  106. $post = UtilService::getMore([['id',0,'empty','新闻数据']],$request);
  107. $data = (new News)->where('id',$post['id'])->find()->toArray();
  108. if(empty($data)) {
  109. return app('json')->fail('请输入正确新闻数据');
  110. }
  111. return app('json')->success($data);
  112. }
  113. public function newsList(Request $request) {
  114. [$page,$data] = (new News)->getList(0,['cate_id'=>2,'is_show'=>1],'6','*','time desc');
  115. return app('json')->success($data);
  116. }
  117. }