successful(StoreProduct::getProductList($data, $request->uid())); } /** * 产品分享二维码 推广员 * @param Request $request * @param $id * @return mixed */ public function code(Request $request) { // if (!$id || !($storeInfo = StoreProduct::getValidProduct($id, 'id'))) return app('json')->fail('商品不存在或已下架'); $id = $request->get('id'); if (!$id) return app('json')->fail('商品不存在或已下架'); $userType = $request->get('user_type', 'wechat'); $type = $request->get('type', 2); $user = $request->user(); $product = null; $stopTime = 0; if ($type == 1) { $product = StoreProduct::where("id={$id}")->find(); } else if ($type == 2) { //拼团商品 $product = StoreCombination::field("c.*,pro.price as p_price,pro.ot_price")->where("c.id={$id}")->alias('c')->join('store_product pro', 'pro.id=c.product_id')->find(); } else if ($type == 3) { //秒杀商品 $stopTime = $request->get('stop_time'); $product = StoreSeckill::field("c.*,pro.price as p_price,pro.ot_price")->where("c.id={$id}")->alias('c')->join('store_product pro', 'pro.id=c.product_id')->find(); } else if ($type == 4) { //直播商品 $product = StoreLiveProduct::field("c.*,pro.price as p_price,pro.ot_price")->where("c.id={$id}")->alias('c')->join('store_product pro', 'pro.id=c.product_id')->find(); } else if ($type == 5) { //试用商品 $product = StoreTryProduct::field("c.*,pro.price as p_price,pro.ot_price")->where("c.id={$id}")->alias('c')->join('store_product pro', 'pro.id=c.product_id')->find(); } if (!$product) { return app('json')->fail('找不到商品'); } $data['title'] = $type == 1 ? $product['store_name'] : $product['title']; $data['image'] = $product['image']; if ($type == 5) { $data['price'] = 0.00; } else { $data['price'] = $product['price']; } // $data['label'] = $type == 2 ? $product['people'] . '人团' : '热卖'; if ($type == 1) { $data['label'] = '热卖'; } else if ($type == 2) { $data['label'] = $product['people'] . '人团'; } else if ($type == 3) { $data['label'] = '秒杀'; } else if ($type == 4) { $data['label'] = '直播'; } else if ($type == 5) { $data['label'] = '试用'; } $data['msg'] = '原价¥' . $product['ot_price']; // return app('json')->success($data); try { switch ($userType) { case 'wechat': //公众号 $siteUrl = sys_config('site_url'); $name = $id . '_product_detail_' . $user['uid'] . '_is_promoter_' . $user['is_promoter'] . "_{$type}" . '_wap.jpg'; $imageInfo = SystemAttachment::getInfo($name, 'name'); if (!$imageInfo) { // $codeUrl = set_http_type($siteUrl . '/activity/group_rule/' . $pinkId . '?spread=' . $user['uid'], 1);//二维码链接 $qurl = $request->param('qurl'); $imageInfo = UtilService::getQRCodePath($qurl, $name); // $imageInfo = UtilService::getQRCodePath($codeUrl, $name); if (is_string($imageInfo)) { return app('json')->fail('二维码生成失败', ['error' => $imageInfo]); } SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2); $url = $imageInfo['dir']; } else $url = $imageInfo['att_dir']; $data['url'] = $url; if ($imageInfo['image_type'] == 1) $data['url'] = $siteUrl . $url; $path = $type == 2 ? 'wap/pink_product/poster' : 'wap/common_product/poster'; $posterImage = UtilService::setShareMarketingPoster($data, $path); if (!is_array($posterImage)) return app('json')->fail('海报生成失败'); SystemAttachment::attachmentAdd($posterImage['name'], $posterImage['size'], $posterImage['type'], $posterImage['dir'], $posterImage['thumb_path'], 1, $posterImage['image_type'], $posterImage['time'], 2); if ($posterImage['image_type'] == 1) $posterImage['dir'] = $siteUrl . $posterImage['dir']; $wapPosterImage = set_http_type($posterImage['dir'], 1);//公众号推广海报 return app('json')->successful(['url' => $wapPosterImage]); // $url = QrcodeService::getWechatQrcodePath($name, '/detail/' . $id . '?spread=' . $user['uid']); // $imageInfo = SystemAttachment::getInfo($name, 'name'); // if ($url === false) // return app('json')->fail('二维码生成失败'); // else // return app('json')->successful(['code' => image_to_base64($url)]); break; case 'routine': //小程序 $name = $id . '_' . $user['uid'] . '_' . $user['is_promoter'] . "_{$type}" . '_product.jpg'; $imageInfo = SystemAttachment::getInfo($name, 'name'); $siteUrl = sys_config('site_url'); if (!$imageInfo) { $r_data = ''; if ($type == 3) { $r_data = 'qr&id=' . $id . '&stoptime=' . $stopTime; } else { $r_data = 'qr&id=' . $id . '&type=' . $type; } $page = ''; if ($type == 1 || $type == 2) { $page = 'pages/product/product'; } else if ($type == 3) { // $page = 'pages/seckill/seckilldetails'; $page = 'pages/seckill/blank'; } else if ($type == 4) { $page = 'pages/product/productLive'; } else if ($type == 5) { $page = 'pages/product/productTrial'; } // if ($user['is_promoter'] || sys_config('store_brokerage_statu') == 2) $r_data .= '&pid=' . $user['uid']; $r_data .= '&pid=' . $user['uid']; if ($type == 3) { //秒杀使用中间页跳转 $o_data = $r_data; $r_data = substr(md5($r_data), 8, 16);; cache($r_data, $o_data, 3600 * 24); //记录在缓存里 } // if ($user['is_promoter'] || sys_config('store_brokerage_statu') == 2) $r_data['pid'] = $user['uid']; $res = \app\models\routine\RoutineCode::getPageCode($page, $r_data, 280); if (!$res) return app('json')->fail('二维码生成失败'); $uploadType = (int)sys_config('upload_type', 1); $upload = new Upload($uploadType, [ 'accessKey' => sys_config('accessKey'), 'secretKey' => sys_config('secretKey'), 'uploadUrl' => sys_config('uploadUrl'), 'storageName' => sys_config('storage_name'), 'storageRegion' => sys_config('storage_region'), ]); $res = $upload->to('routine/product')->validate()->stream($res, $name); if ($res === false) { return app('json')->fail($upload->getError()); } $imageInfo = $upload->getUploadInfo(); $imageInfo['image_type'] = $uploadType; if ($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl . $imageInfo['dir']); else $remoteImage = UtilService::remoteImage($imageInfo['dir']); if (!$remoteImage['status']) return app('json')->fail('小程序二维码未能生成' . $remoteImage['msg']); SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2); $url = $imageInfo['dir']; } else $url = $imageInfo['att_dir']; if ($imageInfo['image_type'] == 1) $data['url'] = $siteUrl . $url; if ($imageInfo['image_type'] == 2) $data['url'] = $url; $path = $type == 2 ? 'routine/pink_product/poster' : 'routine/common_product/poster'; $posterImage = UtilService::setShareMarketingPoster($data, $path); if (!is_array($posterImage)) return app('json')->fail('海报生成失败'); SystemAttachment::attachmentAdd($posterImage['name'], $posterImage['size'], $posterImage['type'], $posterImage['dir'], $posterImage['thumb_path'], 1, $posterImage['image_type'], $posterImage['time'], 2); if ($posterImage['image_type'] == 1) $posterImage['dir'] = $siteUrl . $posterImage['dir']; $routinePosterImage = set_http_type($posterImage['dir'], 0);//小程序推广海报 return app('json')->successful('成功', ['url' => $routinePosterImage]); break; // return app('json')->successful(['code' => $url]); } } catch (\Exception $e) { return app('json')->fail($e->getMessage(), [ 'code' => $e->getCode(), 'line' => $e->getLine(), 'file' => $e->getFile(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } } /** * 秒杀参数解析 * @param Request $request * @return mixed */ public function seckill_analysis(Request $request) { $param = UtilService::getMore([ 'scene' ], $request); $q = cache($param['scene']); return app('json')->success('ok', [ 'q' => $q ]); } /** * 产品详情 * @param Request $request * @param $id * @param int $type * @return mixed */ public function detail(Request $request, $id, $type = 0) { if (!$id || !($storeInfo = StoreProduct::getValidProduct($id))) return app('json')->fail('商品不存在或已下架'); $siteUrl = sys_config('site_url'); $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl); $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl); $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_product_detail_wap.jpg', '/detail/' . $id); $uid = $request->uid(); $data['uid'] = $uid; $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id)); //替换windows服务器下正反斜杠问题导致图片无法显示 $storeInfo['description'] = preg_replace_callback('#]*>#i', function ($imagsSrc) { return isset($imagsSrc[1]) && isset($imagsSrc[0]) ? str_replace($imagsSrc[1], str_replace('\\', '/', $imagsSrc[1]), $imagsSrc[0]) : ''; }, $storeInfo['description']); $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id, $uid, 'collect'); $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like'); list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type); StoreVisit::setView($uid, $id, $storeInfo['cate_id'], 'viwe'); $data['storeInfo'] = StoreProduct::setLevelPrice($storeInfo, $uid, true); $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'], 'id,store_name,image,price,sales,ficti', 4); $data['productAttr'] = $productAttr; $data['productValue'] = $productValue; $data['priceName'] = 0; if ($uid) { $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $uid])->sum('pay_price'); $status = is_brokerage_statu($price); $user = $request->user(); if ($status) { User::where('uid', $uid)->update(['is_promoter' => 1]); $user->is_promoter = 1; } if ($user->is_promoter) { $data['priceName'] = StoreProduct::getPacketPrice($storeInfo, $productValue); } if (!strlen(trim($data['priceName']))) $data['priceName'] = 0; } $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['id']); $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['id'])->count(); if ($data['replyCount']) { $goodReply = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['id'])->where('product_score', 5)->count(); $data['replyChance'] = $goodReply; if ($goodReply) { $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2); $data['replyChance'] = bcmul($data['replyChance'], 100, 2); } } else $data['replyChance'] = 0; $data['mer_id'] = $storeInfo['mer_id']; $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : []; $data['good_list'] = StoreProduct::getGoodList(18, 'image,store_name,price,id,ot_price'); $data['mapKey'] = sys_config('tengxun_map_key'); $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启 $data['activity'] = StoreProduct::activity($data['storeInfo']['id'], false); $data['integral_ratio'] = sys_config('integral_ratio'); return app('json')->successful($data); } /** * 为你推荐 * * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function product_hot(Request $request) { list($page, $limit) = UtilService::getMore([ ['page', 0], ['limit', 0] ], $request, true); if (!$limit) return app('json')->successful([]); $productHot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,ot_price', (int)$page, (int)$limit); if (!empty($productHot)) { foreach ($productHot as $k => $v) { $productHot[$k]['activity'] = StoreProduct::activity($v['id']); } } return app('json')->successful($productHot); } /** * 获取首页推荐不同类型产品的轮播图和产品 * @param Request $request * @param $type * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function groom_list(Request $request, $type) { $info['banner'] = []; $info['list'] = []; if ($type == 1) {//TODO 精品推荐 $info['banner'] = sys_data('routine_home_bast_banner') ?: [];//TODO 首页精品推荐图片 $info['list'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name,sort');//TODO 精品推荐个数 } else if ($type == 2) {//TODO 热门榜单 $info['banner'] = sys_data('routine_home_hot_banner') ?: [];//TODO 热门榜单 猜你喜欢推荐图片 $info['list'] = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid());//TODO 热门榜单 猜你喜欢 } else if ($type == 3) {//TODO 首发新品 $info['banner'] = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品推荐图片 $info['list'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid());//TODO 首发新品 } else if ($type == 4) {//TODO 促销单品 $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片 $info['list'] = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort');//TODO 促销单品 } return app('json')->successful($info); } /** * 产品评价数量和好评度 * @param $id * @return mixed */ public function reply_config($id) { if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); return app('json')->successful(StoreProductReply::productReplyCount($id)); } /** * 获取产品评论 * @param Request $request * @param $id * @param $type * @return mixed */ public function reply_list(Request $request, $id) { list($page, $limit, $type) = UtilService::getMore([ ['page', 0], ['limit', 0], ['type', 0] ], $request, true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); $list = StoreProductReply::getProductReplyList($id, (int)$type, $page, $limit); return app('json')->successful($list); } public function query_by_cateid(Request $request) { $param = UtilService::getMore([ 'cate_id', ['page', 1], ['limit', 10] ], $request); $model = StoreProduct::where('pro.is_del', 0)->where('pro.is_show', 1)->where('pro.mer_id', 0)->alias('pro'); $model->whereIn('pro.id', function ($query) use ($param) { $query->name('store_product_cate')->whereIn('cate_id', function ($q) use ($param) { $q->name('store_category')->where('pid', $param['cate_id'])->field('id')->select(); })->field('product_id')->select(); }); $ids = $model->column('id'); $time = time(); $list = Db::name('store_combination')->alias('c')->field('c.id,c.product_id,c.title store_name,c.image,c.sales,c.price,c.stock')->where("c.is_del=0 and c.is_show=1 and c.start_time<{$time} and c.stop_time>{$time}")->page((int)$param['page'], (int)$param['limit'])->whereIn('c.product_id', $ids)->order('c.sort DESC, c.add_time DESC')->select(); $list = count($list) ? $list->toArray() : []; foreach ($list as $k => $v) { $data = Db::name('store_product')->field('cate_id,ficti')->where('id', $v['product_id'])->find(); $list[$k]['cate_id'] = $data['cate_id']; $list[$k]['ficti'] = $data['ficti']; } return app('json')->successful($list); } }