|
@@ -8,11 +8,12 @@ use addons\unishop\model\Evaluate; |
|
|
use addons\unishop\model\Favorite; |
|
|
use addons\unishop\model\Favorite; |
|
|
use addons\unishop\model\Product as productModel; |
|
|
use addons\unishop\model\Product as productModel; |
|
|
use addons\unishop\model\Coupon; |
|
|
use addons\unishop\model\Coupon; |
|
|
|
|
|
use app\admin\model\Qa; |
|
|
use think\Exception; |
|
|
use think\Exception; |
|
|
|
|
|
|
|
|
class Product extends Base |
|
|
class Product extends Base |
|
|
{ |
|
|
{ |
|
|
protected $noNeedLogin = ['detail', 'lists']; |
|
|
|
|
|
|
|
|
protected $noNeedLogin = ['detail', 'lists',"evaluate"]; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取产品数据 |
|
|
* 获取产品数据 |
|
@@ -20,12 +21,14 @@ class Product extends Base |
|
|
public function detail() |
|
|
public function detail() |
|
|
{ |
|
|
{ |
|
|
$productId = $this->request->get('id'); |
|
|
$productId = $this->request->get('id'); |
|
|
$productId = \addons\unishop\extend\Hashids::decodeHex($productId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($productId)){ |
|
|
|
|
|
$productId = \addons\unishop\extend\Hashids::decodeHex($productId); |
|
|
|
|
|
} |
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
$productModel = new productModel(); |
|
|
$productModel = new productModel(); |
|
|
$data = $productModel->where(['id' => $productId])->cache(10)->find(); |
|
|
$data = $productModel->where(['id' => $productId])->cache(10)->find(); |
|
|
|
|
|
|
|
|
if (!$data) { |
|
|
if (!$data) { |
|
|
$this->error(__('Goods not exist')); |
|
|
$this->error(__('Goods not exist')); |
|
|
} |
|
|
} |
|
@@ -39,23 +42,27 @@ class Product extends Base |
|
|
$data->save(); |
|
|
$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) : ''; |
|
|
|
|
|
|
|
|
// $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->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['evaluate_data']=[ |
|
|
|
|
|
"avg"=>$data["evaluate_avg"], |
|
|
|
|
|
"count"=>$data["evaluate_count"], |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
//优惠券 |
|
|
//优惠券 |
|
|
$data->coupon = (new Coupon)->where('endtime', '>', time()) |
|
|
$data->coupon = (new Coupon)->where('endtime', '>', time()) |
|
@@ -78,7 +85,11 @@ class Product extends Base |
|
|
if ($evaluate) { |
|
|
if ($evaluate) { |
|
|
$data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray(); |
|
|
$data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray(); |
|
|
} |
|
|
} |
|
|
$data = $data->append(['images_text', 'spec_list', 'spec_table_list'])->toArray(); |
|
|
|
|
|
|
|
|
$data = $data->append(['images_text', "detail_images_text",'spec_list', 'spec_table_list'])->toArray(); |
|
|
|
|
|
$qaModel = new Qa(); |
|
|
|
|
|
$qa=$qaModel->where(["product_id"=>$productId])->field("question,answer")->select(); |
|
|
|
|
|
$list = collection($qa)->toArray(); |
|
|
|
|
|
$data['qa']=$list; |
|
|
$this->success('', $data); |
|
|
$this->success('', $data); |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
$this->error($e->getMessage()); |
|
|
$this->error($e->getMessage()); |
|
@@ -202,9 +213,8 @@ class Product extends Base |
|
|
|
|
|
|
|
|
// 评价信息 |
|
|
// 评价信息 |
|
|
$evaluate = (new Evaluate)->alias('e') |
|
|
$evaluate = (new Evaluate)->alias('e') |
|
|
->join('user u', 'e.user_id = u.id') |
|
|
|
|
|
->where(['e.product_id' => $productId]) |
|
|
->where(['e.product_id' => $productId]) |
|
|
->field('u.username,u.avatar,e.*') |
|
|
|
|
|
|
|
|
->field('e.*') |
|
|
->order(['toptime' => 'desc', 'createtime' => 'desc']) |
|
|
->order(['toptime' => 'desc', 'createtime' => 'desc']) |
|
|
->page($page, $pageSize) |
|
|
->page($page, $pageSize) |
|
|
->select(); |
|
|
->select(); |
|
|