|
|
@@ -1,133 +1,66 @@
|
|
|
<?php
|
|
|
-// +----------------------------------------------------------------------
|
|
|
-// | [ WE CAN DO IT MORE SIMPLE ]
|
|
|
-// +----------------------------------------------------------------------
|
|
|
-// | Copyright (c) 2018-2020 rights reserved.
|
|
|
-// +----------------------------------------------------------------------
|
|
|
-// | Author: TABLE ME
|
|
|
-// +----------------------------------------------------------------------
|
|
|
-// | Date: 2020-08-25 17:23
|
|
|
-// +----------------------------------------------------------------------
|
|
|
-declare (strict_types = 1);
|
|
|
+
|
|
|
namespace app\api\controller\v1;
|
|
|
|
|
|
use app\BaseController;
|
|
|
+use app\model\api\Product;
|
|
|
use app\model\api\SiteProduct;
|
|
|
+use app\model\system\Category as CategoryModel;
|
|
|
use app\model\system\News;
|
|
|
+use app\model\system\ProductAttr;
|
|
|
use app\Request;
|
|
|
use library\services\UtilService;
|
|
|
use library\utils\AdvertUtils;
|
|
|
|
|
|
class Index extends BaseController
|
|
|
{
|
|
|
-
|
|
|
/**
|
|
|
- * 获取首页数据
|
|
|
+ * 获取产品分类
|
|
|
*/
|
|
|
- public function getIndex(Request $request) {
|
|
|
- $sassid = $request->site['sassid'];
|
|
|
- $siteProduct = new SiteProduct;
|
|
|
- $siteProduct->setSass($sassid);
|
|
|
- $banner = (new AdvertUtils($sassid))->getData('62');
|
|
|
- $data['banner'] = $banner;
|
|
|
- $data['sort_product'] = $siteProduct->SortList();//排行榜
|
|
|
- foreach ($data['sort_product'] as $k=>$v) {
|
|
|
- $imgAr = explode(',',$v['img']);
|
|
|
- $data['sort_product'][$k]['img'] = empty($imgAr) ? '' : $imgAr[0];
|
|
|
- }
|
|
|
- $newList = $siteProduct->NewsList();//新品上市
|
|
|
- foreach ($newList as $k=>$v) {
|
|
|
- $imgAr = explode(',',$v['img']);
|
|
|
- $newList[$k]['img'] = empty($imgAr) ? '' : $imgAr[0];
|
|
|
- }
|
|
|
- shuffle($newList);
|
|
|
- $data['new_product'] = $newList;
|
|
|
- shuffle($newList);
|
|
|
- $data['hot_product'] = $newList;
|
|
|
- return app('json')->success($data);
|
|
|
+ public function getCategory(){
|
|
|
+ $category = new CategoryModel();
|
|
|
+ $menus = $category->getArMenu('',0,1);
|
|
|
+ return app('json')->success($menus);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- * 获取产品列表数据
|
|
|
- * @param Request $request
|
|
|
+ * 获取产品列表
|
|
|
*/
|
|
|
- public function proList(Request $request){
|
|
|
- $post = UtilService::getMore([
|
|
|
- ['page',1],
|
|
|
- ['warehouse',0],
|
|
|
- ['countType','0'],
|
|
|
- ['type','all'],
|
|
|
- ['pageSize',20]
|
|
|
- ],$request);
|
|
|
- $pageSize = $post['pageSize'];
|
|
|
- $sassid = $request->site['sassid'];
|
|
|
- $siteProduct = new SiteProduct;
|
|
|
- $siteProduct->setSass($sassid);
|
|
|
- list($pageCount,$data) = $siteProduct->getList($post['page'],$post,$pageSize);
|
|
|
- foreach ($data as $k=>$v) {
|
|
|
- $imgAr = explode(',',$v['img']);
|
|
|
- $data[$k]['img'] = empty($imgAr) ? '' : $imgAr[0];
|
|
|
- }
|
|
|
-
|
|
|
- return app('json')->success([
|
|
|
- 'list' => $data,
|
|
|
- 'pageCount' => $pageCount,
|
|
|
- 'pageSize' => $pageSize,
|
|
|
- 'page' => $post['page']
|
|
|
- ]);
|
|
|
+ public function productList(Request $request){
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ ['cid', 0],
|
|
|
+ ['page', 1],
|
|
|
+ ['limit', 24]
|
|
|
+ ], $request);
|
|
|
+ $list = Product::getProductList($data);
|
|
|
+ return app('json')->success($list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 产品详情数据
|
|
|
+ * 商品详情
|
|
|
* @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @param int $type
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function proItem(Request $request) {
|
|
|
- $post = UtilService::getMore([['id',0,'empty','请输入产品ID']],$request);
|
|
|
- $sassid = $request->site['sassid'];
|
|
|
- $siteProduct = new SiteProduct;
|
|
|
- $siteProduct->setSass($sassid);
|
|
|
- $data = $siteProduct->getItem($post['id']);
|
|
|
- if(empty($data)) {
|
|
|
- return app('json')->fail("找不到产品数据");
|
|
|
- } else {
|
|
|
- return app('json')->success($data);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 随机产品
|
|
|
- */
|
|
|
- public function proRand(Request $request) {
|
|
|
- $sassid = $request->site['sassid'];
|
|
|
- $siteProduct = new SiteProduct;
|
|
|
- $siteProduct->setSass($sassid);
|
|
|
- $data = $siteProduct->getRand(5);
|
|
|
- return app('json')->success($data);
|
|
|
+ public function productDetail(Request $request, $id)
|
|
|
+ {
|
|
|
+ if (!$id || !($storeInfo = Product::getValidProduct($id))) return app('json')->fail('商品不存在或已下架');
|
|
|
+ $storeInfo['slider_image'] = json_decode($storeInfo['slider_image'], true);
|
|
|
+ //$storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_product_detail_wap.jpg', '/pages/goods_details/index?id=' . $id);
|
|
|
+ //替换windows服务器下正反斜杠问题导致图片无法显示
|
|
|
+ $storeInfo['description'] = preg_replace_callback('#<img.*?src="([^"]*)"[^>]*>#i', function ($imagsSrc) {
|
|
|
+ return isset($imagsSrc[1]) && isset($imagsSrc[0]) ? str_replace($imagsSrc[1], str_replace('\\', '/', $imagsSrc[1]), $imagsSrc[0]) : '';
|
|
|
+ }, $storeInfo['description']);
|
|
|
+ list($productAttr, $productValue) = ProductAttr::getProductAttrDetail($id, 0, 0);
|
|
|
+ $data['productAttr'] = $productAttr;
|
|
|
+ $prices = array_column($productValue, 'price');
|
|
|
+ array_multisort($prices, SORT_ASC, SORT_NUMERIC, $productValue);
|
|
|
+ $keys = array_keys($productValue);
|
|
|
+ $productValue = array_combine($keys, $productValue);
|
|
|
+ $data['productValue'] = $productValue;
|
|
|
+ $data['priceName'] = 0;
|
|
|
+ return app('json')->successful($data);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新闻数据
|
|
|
- * @param Request $request
|
|
|
- */
|
|
|
- public function news(Request $request) {
|
|
|
- $post = UtilService::getMore([['id',0,'empty','新闻数据']],$request);
|
|
|
- $data = (new News)->where('id',$post['id'])->find()->toArray();
|
|
|
- if(empty($data)) {
|
|
|
- return app('json')->fail('请输入正确新闻数据');
|
|
|
- }
|
|
|
- return app('json')->success($data);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public function newsList(Request $request) {
|
|
|
- [$page,$data] = (new News)->getList(0,['cate_id'=>2,'is_show'=>1],'6','*','time desc');
|
|
|
- return app('json')->success($data);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+}
|