商品详情接口

    /**
 * 商品详情页
 * $goods_id 商品id
 */
public function detail()
{
    $goods_id = $this->input->get('goodsId');
    $user_id  = $this->input->get('userId');
    $user_key = $this->input->get('userKey');
    if (!$goods_id) {
        //提示错误
        error_output("参数错误");
    } else {
        // 是否检查用户已买过
        $is_check_user_bought = 0;
        $goods_info = $this->goods_model->get_detail($goods_id);

        if (!$goods_info) {
            error_output('商品不存在');
        }

        // 如果有传参用户ID和用户Key
        if ($user_id && $user_key) {
            // 验证user_key是否正确
            if (!$this->users_model->get_user_by_user_id_and_user_key($user_id, $user_key)) {
                error_output('userKey验证失败');
            }
            $is_check_user_bought = 1;
        }
        $result = array(
            'status'            => 1,
            'id'                => $goods_info['goods_id'],
            'name'              => $goods_info['goods_name'],
            'desc'              => $goods_info['goods_desc'],
            'marketPrice'       => $goods_info['market_price'],
            'discountPrice1'    => $goods_info['discount_price1'],
            'discountPrice2'    => $goods_info['discount_price2'],
            'stock'             => $goods_info['stock'],
            'payType'           => $goods_info['pay_type'],
            'thumbPicUrl'       => json_decode($goods_info['goods_thumb_img']),
            'picUrls'           => json_decode($goods_info['goods_img_path']),
            'discountStartTime' => $goods_info['discount_start_time']*1000, //毫秒
            'discountEndTime'   => $goods_info['discount_end_time']*1000, //毫秒
        );

        $partner_info = $this->partners_model->get_detail($goods_info['partner_id']);
        if($partner_info)
        {
            $result['partnerName']  = $partner_info['partner_name'];
            $result['partnerLogo']  = $partner_info['partner_logo'];
            //$result['partnerUrl'] =  $partner_info['partner_url'];
            $result['partnerUrl']   =  "http://localhost/skill/partner/bingdian.html";
            $result['weixinCode']   =  $partner_info['weixin_code'];
        }

        $tv_info = $this->tv_model->get_detail($goods_info['tv_id']);
        if($tv_info)
        {
            $result['tvId']         = $tv_info['tv_id'];
            $result['tvName']       = $tv_info['tv_name'];
            $result['tvAbbreviate'] = $tv_info['tv_abbreviate'];
        }

        $array = array(1,'2';34f3);
        $result['isBought'] = 0;
        $result['isKillButNoPay'] = 0;
        if ($is_check_user_bought) {
            // 判断用户是否已秒杀过该商品但是未支付
            if ($this->orders_goods_model->check_user_is_kill_but_no_pay($user_id, $goods_id)) {
                $result['isKillButNoPay'] = 1;
            }
            // 判断用户是否已买过该商品
            if ($this->orders_goods_model->check_user_bought_goods($user_id, $goods_id)) {
                $result['isBought'] = 1;
            }
        }

        json_output($result);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值