Store.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use app\wap\model\store\StoreCategory;
  13. use app\wap\model\store\StoreProduct;
  14. use service\GroupDataService;
  15. use think\Cache;
  16. use think\Request;
  17. use think\Url;
  18. use service\JsonService;
  19. class Store extends AuthController
  20. {
  21. /*
  22. * 白名单
  23. * */
  24. public static function WhiteList()
  25. {
  26. return [
  27. 'index',
  28. 'getCategory',
  29. 'getProductList',
  30. 'detail',
  31. ];
  32. }
  33. /**商城列表
  34. * @param string $keyword
  35. * @return mixed
  36. */
  37. public function index()
  38. {
  39. $banner = json_encode(GroupDataService::getData('product_list_carousel') ?: []);
  40. $this->assign(compact('banner'));
  41. return $this->fetch();
  42. }
  43. /**获取分类
  44. * @throws \think\exception\DbException
  45. */
  46. public function getCategory()
  47. {
  48. $parentCategory = StoreCategory::pidByCategory(0, 'id,cate_name');
  49. $parentCategory=count($parentCategory)>0 ? $parentCategory->toArray() : [];
  50. return JsonService::successful($parentCategory);
  51. }
  52. /**商品列表
  53. * @param string $keyword
  54. * @param int $cId
  55. * @param int $first
  56. * @param int $limit
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @throws \think\exception\DbException
  60. */
  61. public function getProductList($page=1,$limit = 8,$cId = 0)
  62. {
  63. if (!empty($keyword)) $keyword = base64_decode(htmlspecialchars($keyword));
  64. $model = StoreProduct::validWhere();
  65. $model = $model->where('cate_id', $cId);
  66. if (!empty($keyword)) $model->where('keyword|store_name', 'LIKE', "%$keyword%");
  67. $model->order('sort DESC, add_time DESC');
  68. $list = $model->page((int)$page, (int)$limit)->field('id,store_name,image,sales,price,stock,IFNULL(sales,0) + IFNULL(ficti,0) as sales,keyword')->select();
  69. $list=count($list) >0 ? $list->toArray() : [];
  70. return JsonService::successful($list);
  71. }
  72. /**商品详情
  73. * @param int $id
  74. * @return mixed|void
  75. */
  76. public function detail($id = 0)
  77. {
  78. if(!$id) return $this->failed('商品不存在或已下架!',Url::build('store/index'));
  79. $storeInfo = StoreProduct::getValidProduct($id);
  80. if (!$storeInfo) return $this->failed('商品不存在或已下架!',Url::build('store/index'));
  81. $this->assign([
  82. 'storeInfo'=>$storeInfo,
  83. ]);
  84. return $this->fetch();
  85. }
  86. }