&$item) { if ($item['quota'] > 0) { $quota = StoreProductAttrValue::where('product_id', $item['id'])->where('type', 4)->value('SUM(quota)'); $percent = (int)bcmul(bcdiv(bcsub($item['quota'], $quota), $item['quota'], 2), 100, 0); $item['percent'] = $percent; $item['stock'] = $quota; $item['money_type'] = get_money_name($item['money_type']); } else { $item['percent'] = 100; $item['stock'] = 0; $item['money_type'] = get_money_name($item['money_type']); } } } return app('json')->successful($seckillInfo); } /** * 秒杀产品详情 * @param Request $request * @param $id * @return mixed */ public function detail(Request $request, $id) { if (!$id || !($storeInfo = StoreExchange::getValidProduct($id))) return app('json')->fail('商品不存在或已下架!'); $storeInfo = $storeInfo->hidden(['cost', 'add_time', 'is_del'])->toArray(); $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 . '_exchange_detail_wap.jpg', '/activity/exchange_detail/' . $id); $uid = $request->uid(); $storeInfo['uid'] = $uid; $storeInfo['money_type'] = get_money_name($storeInfo['money_type']); $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id, 4)); $data['storeInfo'] = $storeInfo; StoreVisit::setView($uid, $id, $storeInfo['product_id'], 'viwe'); $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['product_id']); $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['product_id'])->count(); if ($data['replyCount']) { $goodReply = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['product_id'])->where('product_score', 5)->count(); $data['replyChance'] = $goodReply; if ($goodReply) { $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2); $data['replyChance'] = bcmul($data['replyChance'], 100, 3); } } else $data['replyChance'] = 0; list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, 0, 4); foreach ($productValue as $k => $v) { $productValue[$k]['product_stock'] = StoreProductAttrValue::where('product_id', $storeInfo['product_id'])->where('suk', $v['suk'])->where('type', 0)->value('stock'); $productValue[$k]['money_type_name'] = get_money_name($productValue[$k]['money_type']); } $data['productAttr'] = $productAttr; $data['productValue'] = $productValue; return app('json')->successful($data); } }