12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\wap\controller;
- use app\wap\model\store\StoreCategory;
- use app\wap\model\store\StoreProduct;
- use service\GroupDataService;
- use think\Cache;
- use think\Request;
- use think\Url;
- use service\JsonService;
- class Store extends AuthController
- {
- /*
- * 白名单
- * */
- public static function WhiteList()
- {
- return [
- 'index',
- 'getCategory',
- 'getProductList',
- 'detail',
- ];
- }
- /**商城列表
- * @param string $keyword
- * @return mixed
- */
- public function index()
- {
- $banner = json_encode(GroupDataService::getData('product_list_carousel') ?: []);
- $this->assign(compact('banner'));
- return $this->fetch();
- }
- /**获取分类
- * @throws \think\exception\DbException
- */
- public function getCategory()
- {
- $parentCategory = StoreCategory::pidByCategory(0, 'id,cate_name');
- $parentCategory=count($parentCategory)>0 ? $parentCategory->toArray() : [];
- return JsonService::successful($parentCategory);
- }
- /**商品列表
- * @param string $keyword
- * @param int $cId
- * @param int $first
- * @param int $limit
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getProductList($page=1,$limit = 8,$cId = 0)
- {
- if (!empty($keyword)) $keyword = base64_decode(htmlspecialchars($keyword));
- $model = StoreProduct::validWhere();
- $model = $model->where('cate_id', $cId);
- if (!empty($keyword)) $model->where('keyword|store_name', 'LIKE', "%$keyword%");
- $model->order('sort DESC, add_time DESC');
- $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();
- $list=count($list) >0 ? $list->toArray() : [];
- return JsonService::successful($list);
- }
- /**商品详情
- * @param int $id
- * @return mixed|void
- */
- public function detail($id = 0)
- {
- if(!$id) return $this->failed('商品不存在或已下架!',Url::build('store/index'));
- $storeInfo = StoreProduct::getValidProduct($id);
- if (!$storeInfo) return $this->failed('商品不存在或已下架!',Url::build('store/index'));
- $this->assign([
- 'storeInfo'=>$storeInfo,
- ]);
- return $this->fetch();
- }
- }
|