Goods.php 3.5 KB
Newer Older
G
goods  
gongfuxiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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
<?php
namespace app\api\controller;

use app\service\GoodsService;

/**
 * 商品
 * @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']))
        {
D
devil_gong 已提交
41
            return DataReturn('参数有误', -1);
G
goods  
gongfuxiang 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        }

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

        // 当前登录用户是否已收藏
        $ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$goods_id, 'user'=>$this->user]);
        $goods[0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0;

        // 商品访问统计
        GoodsService::GoodsAccessCountInc(['goods_id'=>$goods_id]);

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

        // 数据返回
        $result = [
            'goods'                     => $goods[0],
            'common_order_is_booking'   => (int) MyC('common_order_is_booking', 0),
        ];
D
devil_gong 已提交
77
        return DataReturn('success', 0, $result);
G
goods  
gongfuxiang 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    }

    /**
     * 用户商品收藏
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-07-17
     * @desc    description
     */
    public function Favor()
    {
        // 登录校验
        $this->Is_Login();

        // 开始操作
        $params = $this->data_post;
        $params['user'] = $this->user;
D
devil_gong 已提交
96
        return GoodsService::GoodsFavor($params);
G
goods  
gongfuxiang 已提交
97
    }
D
devil_gong 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110

    /**
     * 商品规格类型
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-14
     * @desc    description
     */
    public function SpecType()
    {
        // 开始处理
        $params = $this->data_post;
D
devil_gong 已提交
111
        return GoodsService::GoodsSpecType($params);
D
devil_gong 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125
    }

    /**
     * 商品规格信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-14
     * @desc    description
     */
    public function SpecDetail()
    {
        // 开始处理
        $params = $this->data_post;
D
devil_gong 已提交
126
        return GoodsService::GoodsSpecDetail($params);
D
devil_gong 已提交
127
    }
G
gongfuxiang 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141

    /**
     * 商品分类
     * @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);
D
devil_gong 已提交
142
        return DataReturn('success', 0, $data);
G
gongfuxiang 已提交
143
    }
G
goods  
gongfuxiang 已提交
144 145
}
?>