postData(), [ 'product_status' => 10, 'audit_status' => 10 ]); $page = (new Page())::getDefault(); if (!empty($page)) { if ($page['page_id'] == 10079){ $param['category_id']=197; } } $param['is_gift_pack'] = 0; // 获取列表数据 $model = new ProductModel; $list = $model->getList($param, $this->getUser(false)); $store = SettingModel::getItem('store'); return $this->renderSuccess('', compact('list','store')); } /** * 推荐产品 */ public function recommendProduct($location) { $recommend = SettingModel::getItem('recommend'); $store=SettingModel::getItem('store'); $model = new ProductModel; $is_recommend = RecommendService::checkRecommend($recommend, $location); $list = []; if ($is_recommend) { $list = $model->getRecommendProduct($recommend); } return $this->renderSuccess('', compact('list', 'recommend', 'is_recommend','store')); } /** * 获取商品详情 */ public function detail($product_id, $url) { $params = $this->postData(); // 用户信息 $user = $this->getUser(false); // 商品详情 $model = new ProductModel; $product = $model->getDetails($product_id, $this->getUser(false)); if ($product === false || $product['audit_status'] != 10 || $product['product_status']['value'] != 10) { return $this->renderError($model->getError() ?: '商品信息不存在'); } // 多规格商品sku信息 $specData = $product['spec_type'] == 20 ? $model->getManySpecData($product['spec_rel'], $product['sku']) : null; $isfollow = 0; if ($user) { if (FavoriteModel::detail($product_id, 20, $user['user_id'])) { $isfollow = 1; } } $product['isfollow'] = $isfollow; $dataCoupon['shop_supplier_id'] = $product['shop_supplier_id']; $model = new CouponModel; $couponList = $model->getWaitList($dataCoupon, $this->getUser(false), 1); // 访问记录 (new VisitModel())->addVisit($user, $product['supplier'], $params['visitcode'], $product); // 优惠信息 $discount = [ // 商品满减 'product_reduce' => FullReduceModel::getListByProduct($product_id), // 赠送积分 'give_points' => $this->getGivePoints($product), // 商品优惠券 'product_coupon' => $this->getCouponList($product), ]; //是否显示优惠 $show_discount = false; if(count($discount['product_reduce']) > 0 || $discount['give_points'] > 0 || count($discount['product_coupon']) > 0 ){ $show_discount = true; } //获取商城设置 $store_setting = SettingModel::getItem("store"); $store = ''; //展示门店的信息 if(!empty($store_setting) &&!empty($store_setting["store_type"]) && $store_setting["store_type"] == 1){ $store_id = storeModel::getStoreIdBySupplierId($product['shop_supplier_id']); if($store_id){ $store = storeModel::detail($store_id); } } $cart=new CartModel(); if ($product['spec_type']==20&&!empty($user)){ foreach ($product['sku'] as $key => $value) { $cartData=$cart ->when('spec_sku_id', $value['spec_sku_id']) ->when('product_id', $product_id) ->when('user_id', $user['user_id']) ->find(); if($cartData){ $product['sku'][$key]['cart'] = $cartData; }else{ $product['sku'][$key]['cart'] = ['total_num'=>0]; } } } $page = (new Page())::getDefault(); $is_store_open=true; if (!empty($page)) { if ($page['page_id'] == 10079){ $is_store_open=false; } } return $this->renderSuccess('', [ // 商品详情 'detail' => $product, // 优惠信息 'discount' => $discount, // 显示优惠 'show_discount' => $show_discount, // 购物车商品总数量 'cart_total_num' => $user ? (new CartModel())->getProductNum($user) : 0, // 多规格商品sku信息 'specData' => $specData, // 微信公众号分享参数 'share' => $this->getShareParams($url, $product['product_name'], $product['product_name'], '/pages/product/detail/detail', $product['image'][0]['file_path']), 'couponList' => $couponList, //是否显示店铺信息 'store_open' => $is_store_open&&SettingModel::getStoreOpen(), //显示店铺的类型 'store' => $store, //是否显示下划线价格 'underline_price_show' => SettingModel::getUnderlinePriceShow(), //是否开启客服 'service_open' => SettingModel::getSysConfig()['service_open'], //店铺客服信息 'mp_service' => ServiceModel::detail($product['shop_supplier_id']), //店铺营业状态 'supplier_status' => (new supplier())->supplierStatus($product['shop_supplier_id']), ]); } /** * 赠送积分 */ private function getGivePoints($product) { if ($product['is_points_gift'] == 0) { return 0; } // 积分设置 $setting = SettingModel::getItem('points'); // 条件:后台开启开启购物送积分 if (!$setting['is_shopping_gift']) { return 0; } // 积分赠送比例 $ratio = $setting['gift_ratio'] / 100; // 计算赠送积分数量 return helper::bcmul($product['product_price'], $ratio, 0); } /** * 获取商品可用优惠券 */ private function getCouponList($product) { // 可领取优惠券 $model = new CouponModel; $user = $this->getUser(false); $couponList = $model->getList($user, null, true, $product['shop_supplier_id']); foreach ($couponList as $item){ // 限制商品 if($item['apply_range'] == 20){ $product_ids = explode(',', $item['product_ids']); if(!in_array($product['product_id'], $product_ids)){ unset($item); } } } return $couponList; } /** * 预告产品 */ public function previewProduct() { // 整理请求的参数 $param = array_merge($this->postData(), [ 'type' => 'preview', ]); // 获取列表数据 $model = new ProductModel; $list = $model->getList($param, $this->getUser(false)); return $this->renderSuccess('', compact('list')); } /** * 生成商品海报 */ public function poster($product_id, $source) { // 商品详情 $detail = ProductModel::detail($product_id); $Qrcode = new ProductService($detail, $this->getUser(false), $source); return $this->renderSuccess('', [ 'qrcode' => $Qrcode->getImage(), ]); } }