Goods.php 5.3 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
devil_gong 已提交
5
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6 7 8 9 10 11 12
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\api\controller;

13
use app\service\GoodsService;
G
gongfuxiang 已提交
14
use app\service\GoodsCommentsService;
D
v1.2.0  
devil_gong 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

/**
 * 商品
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class Goods extends Common
{
    /**
     * [__construct 构造方法]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-03T12:39:08+0800
     */
    public function __construct()
    {
        // 调用父类前置方法
        parent::__construct();
    }

    /**
     * 获取商品详情
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-07-12
     * @desc    description
     */
    public function Detail()
    {
        // 参数
        if(empty($this->data_post['goods_id']))
        {
            return DataReturn('参数有误', -1);
        }

G
gongfuxiang 已提交
54 55 56
        // 商品详情方式
        $is_use_mobile_detail = intval(MyC('common_app_is_use_mobile_detail'));

D
v1.2.0  
devil_gong 已提交
57 58 59 60 61 62 63 64 65
        // 获取商品
        $goods_id = intval($this->data_post['goods_id']);
        $params = [
            'where' => [
                'id' => $goods_id,
                'is_delete_time' => 0,
            ],
            'is_photo' => true,
            'is_spec' => true,
G
gongfuxiang 已提交
66
            'is_content_app' => ($is_use_mobile_detail == 1),
D
v1.2.0  
devil_gong 已提交
67
        ];
68 69
        $ret = GoodsService::GoodsList($params);
        if(empty($ret['data'][0]) || $ret['data'][0]['is_delete_time'] != 0)
D
v1.2.0  
devil_gong 已提交
70 71 72
        {
            return DataReturn('商品不存在或已删除', -1);
        }
G
gongfuxiang 已提交
73 74 75 76 77 78 79 80 81 82

        // 商品详情处理
        if($is_use_mobile_detail == 1)
        {
            unset($ret['data'][0]['content_web']);
        } else {
            // 标签处理,兼容小程序rich-text
            $search = [
                '<img ',
                '<section',
D
1.6  
devil_gong 已提交
83 84 85
                '/section>',
                '<p>',
                '<div>',
G
gongfuxiang 已提交
86 87 88 89 90
            ];
            $replace = [
                '<img style="max-width:100%;margin:0;display:block;" ',
                '<div',
                '/div>',
D
1.6  
devil_gong 已提交
91 92
                '<p style="margin:0;">',
                '<div style="margin:0;">',
G
gongfuxiang 已提交
93 94 95
            ];
            $ret['data'][0]['content_web'] = str_replace($search, $replace, $ret['data'][0]['content_web']);
        }
D
v1.2.0  
devil_gong 已提交
96 97 98

        // 当前登录用户是否已收藏
        $ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$goods_id, 'user'=>$this->user]);
99
        $ret['data'][0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0;
D
v1.2.0  
devil_gong 已提交
100

G
gongfuxiang 已提交
101 102 103
        // 商品评价总数
        $ret['data'][0]['comments_count'] = GoodsCommentsService::GoodsCommentsTotal(['goods_id'=>$goods_id, 'is_show'=>1]);

D
v1.2.0  
devil_gong 已提交
104 105 106 107 108 109 110 111
        // 商品访问统计
        GoodsService::GoodsAccessCountInc(['goods_id'=>$goods_id]);

        // 用户商品浏览
        GoodsService::GoodsBrowseSave(['goods_id'=>$goods_id, 'user'=>$this->user]);

        // 数据返回
        $result = [
G
gongfuxiang 已提交
112 113 114 115
            'goods'                             => $ret['data'][0],
            'common_order_is_booking'           => (int) MyC('common_order_is_booking', 0),
            'common_app_is_use_mobile_detail'   => $is_use_mobile_detail,
            'common_app_is_online_service'      => (int) MyC('common_app_is_online_service', 0),
D
v1.2.0  
devil_gong 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
        ];
        return DataReturn('success', 0, $result);
    }

    /**
     * 用户商品收藏
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-07-17
     * @desc    description
     */
    public function Favor()
    {
        // 登录校验
G
gongfuxiang 已提交
131
        $this->IsLogin();
D
v1.2.0  
devil_gong 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

        // 开始操作
        $params = $this->data_post;
        $params['user'] = $this->user;
        return GoodsService::GoodsFavor($params);
    }

    /**
     * 商品规格类型
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-14
     * @desc    description
     */
    public function SpecType()
    {
        // 开始处理
        $params = $this->data_post;
        return 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_post;
        return GoodsService::GoodsSpecDetail($params);
    }

    /**
     * 商品分类
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-14
     * @desc    description
     */
    public function Category()
    {
        // 开始处理
        $params = $this->data_post;
        $data = GoodsService::GoodsCategory($params);
        return DataReturn('success', 0, $data);
    }
}
?>