|
@@ -16,7 +16,7 @@ use think\Db;
|
|
*/
|
|
*/
|
|
class Product extends Base
|
|
class Product extends Base
|
|
{
|
|
{
|
|
- protected $noNeedLogin = ['detail', 'lists','index_sifang'];
|
|
|
|
|
|
+ protected $noNeedLogin = ['detail', 'lists','index_sifang','cate_list'];
|
|
|
|
|
|
/**
|
|
/**
|
|
* @ApiTitle (产品详情)
|
|
* @ApiTitle (产品详情)
|
|
@@ -49,69 +49,68 @@ class Product extends Base
|
|
*/
|
|
*/
|
|
public function detail()
|
|
public function detail()
|
|
{
|
|
{
|
|
- $productId = $this->request->get('id');
|
|
|
|
-// $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
|
|
|
|
|
|
+ $productId = $this->request->request('id');
|
|
|
|
+ $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
|
|
|
|
|
|
- try {
|
|
|
|
|
|
|
|
- $productModel = new productModel();
|
|
|
|
- $data = $productModel->where(['id' => $productId])->cache(10)->find();
|
|
|
|
- if (!$data) {
|
|
|
|
- $this->error(__('Goods not exist'));
|
|
|
|
- }
|
|
|
|
- if ($data['switch'] == productModel::SWITCH_OFF) {
|
|
|
|
- $this->error(__('Goods are off the shelves'));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- // 真实浏览量加一
|
|
|
|
- $data->real_look++;
|
|
|
|
- $data->look++;
|
|
|
|
- $data->save();
|
|
|
|
-
|
|
|
|
- //服务
|
|
|
|
- $server = explode(',', $data->server);
|
|
|
|
- $configServer = json_decode(Config::getByName('server')['value'],true);
|
|
|
|
- $serverValue = [];
|
|
|
|
- foreach ($server as $k => $v) {
|
|
|
|
- if (isset($configServer[$v])) {
|
|
|
|
- $serverValue[] = $configServer[$v];
|
|
|
|
- }
|
|
|
|
|
|
+ $productModel = new productModel();
|
|
|
|
+ $data = $productModel->where(['id' => $productId])->cache(10)->find();
|
|
|
|
+ if (!$data) {
|
|
|
|
+ $this->error(__('Goods not exist'));
|
|
|
|
+ }
|
|
|
|
+ if ($data['switch'] == productModel::SWITCH_OFF) {
|
|
|
|
+ $this->error(__('Goods are off the shelves'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 真实浏览量加一
|
|
|
|
+ $data->real_look++;
|
|
|
|
+ $data->look++;
|
|
|
|
+ $data->save();
|
|
|
|
+
|
|
|
|
+ //服务
|
|
|
|
+ /*$server = explode(',', $data->server);
|
|
|
|
+ $configServer = json_decode(Config::getByName('server')['value'],true);
|
|
|
|
+ $serverValue = [];
|
|
|
|
+ foreach ($server as $k => $v) {
|
|
|
|
+ if (isset($configServer[$v])) {
|
|
|
|
+ $serverValue[] = $configServer[$v];
|
|
}
|
|
}
|
|
- $data->server = count($serverValue) ? implode(' · ', $serverValue) : '';
|
|
|
|
|
|
+ }
|
|
|
|
+ $data->server = count($serverValue) ? implode(' · ', $serverValue) : '';*/
|
|
|
|
|
|
- // 默认没有收藏
|
|
|
|
- $data->favorite = false;
|
|
|
|
|
|
+ // 默认没有收藏
|
|
|
|
+ $data->favorite = false;
|
|
|
|
|
|
- // 评价
|
|
|
|
- $data['evaluate_data'] = (new Evaluate)->where(['product_id' => $productId])
|
|
|
|
- ->field('COUNT(*) as count, IFNULL(CEIL(AVG(rate)/5*100),0) as avg')
|
|
|
|
- ->cache(10)->find();
|
|
|
|
|
|
+ // 评价
|
|
|
|
+ $data['evaluate_data'] = (new Evaluate)->where(['product_id' => $productId])
|
|
|
|
+ ->field('COUNT(*) as count, IFNULL(CEIL(AVG(rate)/5*100),0) as avg')
|
|
|
|
+ ->cache(10)->find();
|
|
|
|
|
|
- //优惠券
|
|
|
|
- $data->coupon = (new Coupon)->where('endtime', '>', time())
|
|
|
|
- ->where(['switch' => Coupon::SWITCH_ON])->cache(10)->order('weigh DESC')->select();
|
|
|
|
|
|
|
|
- // 是否已收藏
|
|
|
|
- if ($this->auth->id) {
|
|
|
|
- $data->favorite = (new Favorite)->where(['user_id' => $this->auth->id, 'product_id' => $productId])->count();
|
|
|
|
- }
|
|
|
|
|
|
+ //优惠券
|
|
|
|
+ /*$data->coupon = (new Coupon)->where('endtime', '>', time())
|
|
|
|
+ ->where(['switch' => Coupon::SWITCH_ON])->cache(10)->order('weigh DESC')->select();*/
|
|
|
|
|
|
- // 购物车数量
|
|
|
|
- $data->cart_num = (new \addons\unishop\model\Cart)->where(['user_id' => $this->auth->id])->count();
|
|
|
|
-
|
|
|
|
- // 评价信息
|
|
|
|
- $evaluate = (new Evaluate)->alias('e')
|
|
|
|
- ->join('user u', 'e.user_id = u.id')
|
|
|
|
- ->where(['e.product_id' => $productId, 'toptime' => ['>', Evaluate::TOP_OFF]])
|
|
|
|
- ->field('u.username,u.avatar,e.*')
|
|
|
|
- ->order(['toptime' => 'desc', 'createtime' => 'desc'])->select();
|
|
|
|
- if ($evaluate) {
|
|
|
|
- $data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray();
|
|
|
|
- }
|
|
|
|
- $data = $data->append(['images_text', 'spec_list', 'spec_table_list'])->toArray();
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
- $this->error($e->getMessage());
|
|
|
|
|
|
+ // 是否已收藏
|
|
|
|
+ if ($this->auth->id) {
|
|
|
|
+ $data->favorite = (new Favorite)->where(['user_id' => $this->auth->id, 'product_id' => $productId])->count();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 购物车数量
|
|
|
|
+// $data->cart_num = (new \addons\unishop\model\Cart)->where(['user_id' => $this->auth->id])->count();
|
|
|
|
+
|
|
|
|
+ // 评价信息
|
|
|
|
+ $evaluate = (new Evaluate)->alias('e')
|
|
|
|
+ ->join('user u', 'e.user_id = u.id')
|
|
|
|
+ ->where(['e.product_id' => $productId, 'toptime' => ['>', Evaluate::TOP_OFF]])
|
|
|
|
+ ->field('u.username,u.avatar,e.*')
|
|
|
|
+ ->order(['toptime' => 'desc', 'createtime' => 'desc'])->limit(2)->select();
|
|
|
|
+ if ($evaluate) {
|
|
|
|
+ $data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray();
|
|
|
|
+ }
|
|
|
|
+ $data = $data->append(['images_text', 'spec_list', 'spec_table_list'])->toArray();
|
|
|
|
+
|
|
$this->success('', $data);
|
|
$this->success('', $data);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -141,12 +140,16 @@ class Product extends Base
|
|
$desc = $this->request->request('desc', 'desc');
|
|
$desc = $this->request->request('desc', 'desc');
|
|
|
|
|
|
$cate_id = $this->request->request('cate_id',0,'intval');
|
|
$cate_id = $this->request->request('cate_id',0,'intval');
|
|
|
|
+ $tag_id = $this->request->request('tag_id',0,'intval');
|
|
|
|
|
|
$productModel = new productModel();
|
|
$productModel = new productModel();
|
|
|
|
|
|
if($cate_id != 0){
|
|
if($cate_id != 0){
|
|
$productModel->where(['cate_id' => $cate_id]);
|
|
$productModel->where(['cate_id' => $cate_id]);
|
|
}
|
|
}
|
|
|
|
+ if($tag_id != 0){
|
|
|
|
+ $productModel->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => $tag_id]);
|
|
|
|
+ }
|
|
|
|
|
|
$result = $productModel
|
|
$result = $productModel
|
|
->where(['switch' => productModel::SWITCH_ON])
|
|
->where(['switch' => productModel::SWITCH_ON])
|
|
@@ -165,24 +168,31 @@ class Product extends Base
|
|
|
|
|
|
//首页商品四方列表
|
|
//首页商品四方列表
|
|
public function index_sifang(){
|
|
public function index_sifang(){
|
|
|
|
+ $productModel = new productModel();
|
|
//四个标签的商品
|
|
//四个标签的商品
|
|
- $tag1 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 1])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
- $tag2 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 2])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
- $tag3 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 3])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
- $tag4 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 4])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
|
|
+ $tag1 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 1])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
+ $tag2 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 2])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
+ $tag3 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 3])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
+ $tag4 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 4])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = [
|
|
$result = [
|
|
- 'tuijian' => list_domain_image($tag1,['image']),
|
|
|
|
- 'remen' => list_domain_image($tag2,['image']),
|
|
|
|
- 'shoufa' => list_domain_image($tag3,['image']),
|
|
|
|
- 'cuxiao' => list_domain_image($tag4,['image']),
|
|
|
|
|
|
+ 'tuijian' => $tag1,
|
|
|
|
+ 'remen' => $tag2,
|
|
|
|
+ 'shoufa' => $tag3,
|
|
|
|
+ 'cuxiao' => $tag4,
|
|
];
|
|
];
|
|
|
|
|
|
$this->success(1,$result);
|
|
$this->success(1,$result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //分类列表
|
|
|
|
+ public function cate_list(){
|
|
|
|
+ $list = Db::name('unishop_cate')->order('id asc')->select();
|
|
|
|
+ $this->success(1,$list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|