|
|
|
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\wap\controller;
|
|
|
|
|
|
|
|
use app\wap\model\special\SpecialSubject;
|
|
|
|
use app\wap\model\store\StoreCategory;
|
|
|
|
use app\wap\model\store\StoreEntityCategory;
|
|
|
|
use app\wap\model\store\StoreProduct;
|
|
|
|
use service\GroupDataService;
|
|
|
|
use service\SystemConfigService;
|
|
|
|
use app\wap\model\topic\Relation;
|
|
|
|
use think\Cache;
|
|
|
|
use think\Request;
|
|
|
|
use think\Url;
|
|
|
|
use service\JsonService;
|
|
|
|
|
|
|
|
/**商品控制器
|
|
|
|
* Class Store
|
|
|
|
* @package app\wap\controller
|
|
|
|
*/
|
|
|
|
class Store extends AuthController
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 白名单
|
|
|
|
* */
|
|
|
|
public static function WhiteList()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'index',
|
|
|
|
'index_api',
|
|
|
|
'getCategory',
|
|
|
|
'getProductList',
|
|
|
|
'getAssociatedTopics',
|
|
|
|
'detail',
|
|
|
|
'detail_api'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**商城列表
|
|
|
|
* @param string $keyword
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$banner = json_encode(GroupDataService::getData('product_list_carousel') ?: []);
|
|
|
|
$this->assign(compact('banner'));
|
|
|
|
return $this->fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index_api()
|
|
|
|
{
|
|
|
|
$banner = GroupDataService::getData('product_list_carousel') ?: [];
|
|
|
|
return JsonService::successful($banner);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**获取分类 new
|
|
|
|
* @throws \think\exception\DbException
|
|
|
|
*/
|
|
|
|
public function getEntityCategory()
|
|
|
|
{
|
|
|
|
$category = StoreEntityCategory::with('children')->where(['is_show' => 1, 'is_del' => 0])->order('sort desc,id desc')->where('grade_id', 0)->select();
|
|
|
|
$recommend = StoreEntityCategory::where(['is_show' => 1, 'is_del' => 0, 'is_recommend' => 1])->where('grade_id', 'neq', 0)->order('sort desc,id desc')->select();
|
|
|
|
return JsonService::successful([
|
|
|
|
'category_list' => $category->toArray(),
|
|
|
|
'recommend' => $recommend->toArray()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**获取分类
|
|
|
|
* @throws \think\exception\DbException
|
|
|
|
*/
|
|
|
|
public function getCategory()
|
|
|
|
{
|
|
|
|
$cateogry = StoreCategory::with('children')->where(['is_show' => 1])->order('sort desc,id desc')->where('pid', 0)->select();
|
|
|
|
return JsonService::successful($cateogry->toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**商品列表
|
|
|
|
* @param int $page
|
|
|
|
* @param int $limit
|
|
|
|
* @param int $cId
|
|
|
|
* @param string $keyword
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
public function getProductList($page = 1, $limit = 8, $cId = 0, $keyword = '')
|
|
|
|
{
|
|
|
|
if (!empty($keyword)) $keyword = base64_decode(htmlspecialchars($keyword));
|
|
|
|
$model = StoreProduct::validWhere();
|
|
|
|
if (!empty($cId)) $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,mer_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 $page
|
|
|
|
* @param int $limit
|
|
|
|
* @param int $cId
|
|
|
|
* @param string $keyword
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
public function getRecommendProductList($page = 1, $limit = 8, $cId = 0, $keyword = '')
|
|
|
|
{
|
|
|
|
if (!empty($keyword)) $keyword = base64_decode(htmlspecialchars($keyword));
|
|
|
|
$model = StoreProduct::validWhere();
|
|
|
|
if (!empty($cId)) $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,mer_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) $this->failed('参数错误!', Url::build('store/index'));
|
|
|
|
$storeInfo = StoreProduct::getValidProduct($id);
|
|
|
|
if (!$storeInfo) $this->failed('商品不存在或已下架!', Url::build('store/index'));
|
|
|
|
$site_url = SystemConfigService::get('site_url') . Url::build('store/detail') . '?id=' . $id . '&spread_uid=' . $this->uid;
|
|
|
|
$this->assign(['storeInfo' => $storeInfo, 'site_url' => $site_url]);
|
|
|
|
return $this->fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function detail_api($id = 0)
|
|
|
|
{
|
|
|
|
if (!$id) return JsonService::fail("商品不存在!");
|
|
|
|
$storeInfo = StoreProduct::getValidProduct($id);
|
|
|
|
if (!$storeInfo) return JsonService::fail('商品不存在或已下架!');
|
|
|
|
$site_url = SystemConfigService::get('site_url') . '/h5#/pages/store/detail?id=' . $id . '&spread_uid=' . $this->uid;
|
|
|
|
|
|
|
|
return JsonService::successful([
|
|
|
|
'site_url' => $site_url,
|
|
|
|
'storeInfo' => $storeInfo,
|
|
|
|
'isShareDisplaySwitch' => SystemConfigService::get('share_display_switch'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**获取关联专题
|
|
|
|
* @param int $id
|
|
|
|
*/
|
|
|
|
public function getAssociatedTopics($id = 0, $page = 1, $list = 10)
|
|
|
|
{
|
|
|
|
if (!$id) return JsonService::fail('参数错误!');
|
|
|
|
$data = Relation::getRelationSpecial(5, $id, $page, $list);
|
|
|
|
foreach ($data as $key => &$item) {
|
|
|
|
if (is_string($item['label'])) $item['label'] = json_decode($item['label'], true);
|
|
|
|
}
|
|
|
|
return JsonService::successful($data);
|
|
|
|
}
|
|
|
|
}
|