<?php
namespace app\index\controller;
use app\index\controller\Common;
use app\service\ApiService;
use app\service\SeoService;
use app\service\GoodsService;
use app\service\GoodsCommentsService;
use app\service\GoodsBrowseService;
use app\service\GoodsFavorService;
use app\service\GoodsCartService;
use app\service\BreadcrumbService;
* 商品详情
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Goods extends Common
{
* 构造方法
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-11-30
* @desc description
*/
public function __construct()
{
parent::__construct();
}
* 详情
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-12-02T23:42:49+0800
*/
public function Index()
{
$goods_id = isset($this->data_request['id']) ? $this->data_request['id'] : 0;
$params = [
'where' => [
['id', '=', $goods_id],
['is_delete_time', '=', 0],
],
'is_photo' => 1,
'is_spec' => 1,
'is_params' => 1,
'is_favor' => 1,
];
$ret = GoodsService::GoodsList($params);
if(!empty($ret['data']) && !empty($ret['data'][0]))
{
$goods = $ret['data'][0];
$goods['comments_count'] = GoodsCommentsService::GoodsCommentsTotal(['goods_id'=>$goods_id, 'is_show'=>1]);
$goods['favor_count'] = GoodsFavorService::GoodsFavorTotal(['goods_id'=>$goods_id]);
$assign = [
'goods' => $goods,
'buy_left_nav' => GoodsService::GoodsBuyLeftNavList($goods),
'buy_button' => GoodsService::GoodsBuyButtonList($goods),
'buy_to_link' => GoodsService::GoodsBuyToLinkData($goods),
'middle_tabs_nav' => GoodsService::GoodsDetailMiddleTabsNavList($goods),
'breadcrumb_data' => BreadcrumbService::Data('GoodsDetail', ['goods'=>$goods]),
'is_load_imagezoom' => 1,
'is_load_ckplayer' => 1,
];
$assign['common_is_goods_detail_content_show_photo'] = MyC('common_is_goods_detail_content_show_photo', 0, true);
if(!empty($assign['middle_tabs_nav']) && !empty($assign['middle_tabs_nav']['type']))
{
if(in_array('comments', $assign['middle_tabs_nav']['type']))
{
$assign['goods_score'] = GoodsCommentsService::GoodsCommentsScore($goods_id);
}
if(!empty($assign['middle_tabs_nav']) && in_array('guess_you_like', $assign['middle_tabs_nav']['type']))
{
$assign['guess_you_like'] = GoodsService::GoodsDetailGuessYouLikeData($goods['id'], ['is_spec'=>0, 'is_cart'=>0]);
}
}
$assign['left_goods'] = GoodsService::GoodsDetailSeeingYouData($goods['id'], ['is_spec'=>0, 'is_cart'=>0]);
GoodsService::GoodsAccessCountInc(['goods_id'=>$goods_id]);
GoodsBrowseService::GoodsBrowseSave(['goods_id'=>$goods_id, 'user'=>$this->user]);
$seo_title = empty($goods['seo_title']) ? $goods['title'] : $goods['seo_title'];
$assign['home_seo_site_title'] = SeoService::BrowserSeoTitle($seo_title, 2);
if(!empty($goods['seo_keywords']))
{
$assign['home_seo_site_keywords'] = $goods['seo_keywords'];
}
if(!empty($goods['seo_desc']) || !empty($goods['simple_desc']))
{
$assign['home_seo_site_description'] = empty($goods['seo_desc']) ? $goods['simple_desc'] : $goods['seo_desc'];
}
MyViewAssign($assign);
$this->PluginsHook($goods_id, $goods);
return MyView();
}
MyViewAssign('msg', MyLang('goods.goods_no_data_tips'));
return MyView('/public/tips_error');
}
* 加入购物车页面
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-02-22T16:50:32+0800
*/
public function CartInfo()
{
$goods_id = isset($this->data_request['id']) ? $this->data_request['id'] : 0;
$params = [
'where' => [
['id', '=', $goods_id],
['is_delete_time', '=', 0],
],
'is_spec' => 1,
];
$ret = GoodsService::GoodsList($params);
if(!empty($ret['data']) && !empty($ret['data'][0]))
{
$goods = $ret['data'][0];
$buy_button = GoodsService::GoodsBuyButtonList($goods);
MyViewAssign([
'goods' => $goods,
'buy_button' => $buy_button,
'is_header' => 0,
'is_footer' => 0,
]);
return MyView();
}
MyViewAssign([
'msg' => MyLang('goods.goods_no_data_tips'),
'is_header' => 0,
'is_footer' => 0,
'is_to_home' => 0,
]);
return MyView('/public/tips_error');
}
* 商品收藏
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
*/
public function Favor()
{
IsUserLogin();
$params = $this->data_request;
$params['user'] = $this->user;
return ApiService::ApiDataReturn(GoodsFavorService::GoodsFavorCancel($params));
}
* 商品规格类型
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-14
* @desc description
*/
public function SpecType()
{
$params = $this->data_request;
return ApiService::ApiDataReturn(GoodsService::GoodsSpecType($params));
}
* 商品规格信息
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-14
* @desc description
*/
public function SpecDetail()
{
$params = $this->data_request;
return ApiService::ApiDataReturn(GoodsService::GoodsSpecDetail($params));
}
* 商品数量选择
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-14
* @desc description
*/
public function Stock()
{
$params = $this->data_request;
return ApiService::ApiDataReturn(GoodsService::GoodsStock($params));
}
* 商品评论
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-13T21:47:41+0800
*/
public function Comments()
{
$params = $this->data_request;
if(empty($params['goods_id']))
{
return ApiService::ApiDataReturn(DataReturn(MyLang('params_error_tips'), -1));
}
$where = [
'goods_id' => $params['goods_id'],
'is_show' => 1,
];
$total = GoodsCommentsService::GoodsCommentsTotal($where);
$page_total = ceil($total/$this->page_size);
$start = intval(($this->page-1)*$this->page_size);
$data = [];
if($total > 0)
{
$data_params = [
'm' => $start,
'n' => $this->page_size,
'where' => $where,
'is_public' => 1,
];
$ret = GoodsCommentsService::GoodsCommentsList($data_params);
if(!empty($ret['data']))
{
$data = $ret['data'];
}
}
$result = [
'number' => $this->page_size,
'total' => $total,
'page_total' => $page_total,
'data' => MyView('', ['data'=>$data]),
];
return ApiService::ApiDataReturn(DataReturn('success', 0, $result));
}
* 二维码数据
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2026-02-28
* @desc description
*/
public function QrcodeData()
{
if(!empty($this->data_request['id']))
{
$params = [
'where' => [
['id', '=', $this->data_request['id']],
['is_delete_time', '=', 0],
],
'is_photo' => 1,
'is_spec' => 1,
'is_params' => 1,
'is_favor' => 1,
];
$ret = GoodsService::GoodsList($params);
if(!empty($ret['data']) && !empty($ret['data'][0]))
{
return ApiService::ApiDataReturn(GoodsService::GoodsQrcode($ret['data'][0], $this->user));
}
}
return ApiService::ApiDataReturn(DataReturn(MyLang('no_goods'), -1));
}
* 钩子处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-04-22
* @desc description
* @param [int] $goods_id [商品id]
* @param [array] $params [输入参数]
*/
private function PluginsHook($goods_id, &$goods)
{
$hook_arr = [
'plugins_view_goods_detail_photo_within',
'plugins_view_goods_detail_photo_bottom',
'plugins_view_goods_detail_base_top',
'plugins_view_goods_detail_panel_bottom',
'plugins_view_goods_detail_base_sku_top',
'plugins_view_goods_detail_base_inventory_top',
'plugins_view_goods_detail_base_inventory_bottom',
'plugins_view_goods_detail_buy_nav_top',
'plugins_view_goods_detail_right_content_top',
'plugins_view_goods_detail_right_content_bottom',
'plugins_view_goods_detail_right_content_inside_top',
'plugins_view_goods_detail_right_content_inside_bottom',
'plugins_view_goods_detail_base_bottom',
'plugins_view_goods_detail_tabs_top',
'plugins_view_goods_detail_tabs_content',
'plugins_view_goods_detail_tabs_comments_top',
'plugins_view_goods_detail_tabs_comments_bottom',
'plugins_view_goods_detail_tabs_guess_like_top',
'plugins_view_goods_detail_tabs_guess_like_bottom',
'plugins_view_goods_detail_tabs_bottom',
'plugins_view_goods_detail_content_top',
'plugins_view_goods_detail_content_bottom',
'plugins_view_goods_detail_left_top',
'plugins_view_goods_detail_title',
'plugins_view_goods_detail_panel_original_price_top',
'plugins_view_goods_detail_panel_price_top',
'plugins_view_goods_detail_panel_price_bottom',
'plugins_view_goods_detail_base_buy_nav_min_inside_begin',
'plugins_view_goods_detail_base_buy_nav_min_inside',
];
$assign = [];
foreach($hook_arr as $hook_name)
{
$assign[$hook_name.'_data'] = MyEventTrigger($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
'goods_id' => $goods_id,
'goods' => &$goods,
]);
}
MyViewAssign($assign);
}
}
?>