getList(['listType' => 'on_sale'], 8)->toArray()['data']; $bestseller = $model->getList(['sortType' => 'sales'], 8)->toArray()['data']; //$superDeals = $model->getList(['categoryId' => '10002',], 8)->toArray()['data']; $superDeals = $bestseller; $newGoodsId = array_column($newArrival, 'goods_id'); $bestGoodsId = array_column($bestseller, 'goods_id'); $superDealsGoodsId = array_column($superDeals, 'goods_id'); //获取评价数量 $goodsIds = array_unique(array_merge($newGoodsId, $bestGoodsId, $superDealsGoodsId)); $commentModel = new CommentModel(); $rows = $commentModel->rowsTotalBatch($goodsIds)->toArray(); $rowsByGoodsId = array_column($rows, 'cnt', 'goods_id'); //获取评论分数 $commentScores = $commentModel->getTotalAll($goodsIds)->toArray(); $scoresByGoodsId = array_column($commentScores, 'score_total', 'goods_id'); //dd($rowsByGoodsId); //可考虑缓存 foreach ($newArrival as &$item) { $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0; $temp = bcmul($item['comment_cnt'], 10, 0); if ($temp) { $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0); } else { $item['avg_score'] = 5; } } Cache::set('index_newArrival', json_encode($newArrival), 1200); foreach ($bestseller as &$item) { $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0; $temp = bcmul($item['comment_cnt'], 10, 0); if ($temp) { $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0); } else { $item['avg_score'] = 5; } } Cache::set('index_bestseller', json_encode($bestseller), 1200); foreach ($superDeals as &$item) { $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0; $temp = bcmul($item['comment_cnt'], 10, 0); if ($temp) { $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0); } else { $item['avg_score'] = 5; } } Cache::set('index_superDeals', json_encode($superDeals), 1200); $model = new ArticleModel; $article = $model->getList(0, 5)->toArray()['data']; foreach ($article as &$datum) { $datum['year'] = substr($datum['create_time'], 0, 4); $datum['month_day'] = substr($datum['create_time'], 5, 5); $datum['date'] = substr($datum['create_time'], 0, 10); } Cache::set('index_article', json_encode($article), 1200); } $superDeals1 = $superDeals2 = []; isset($superDeals[0]) && $superDeals1[] = $superDeals[0]; isset($superDeals[1]) && $superDeals1[] = $superDeals[1]; isset($superDeals[2]) && $superDeals1[] = $superDeals[2]; isset($superDeals[3]) && $superDeals1[] = $superDeals[3]; isset($superDeals[4]) && $superDeals2[] = $superDeals[4]; isset($superDeals[5]) && $superDeals2[] = $superDeals[5]; isset($superDeals[6]) && $superDeals2[] = $superDeals[6]; isset($superDeals[7]) && $superDeals2[] = $superDeals[7]; return view('/index/index', [ 'newGoods' => $newArrival, 'bestseller' => $bestseller, 'superDealsOne' => $superDeals1, 'superDealsTwo' => $superDeals2, 'article' => $article, ]); } /** * 产品详情页 * @return \think\response\Redirect|View * @throws \cores\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function productDetails($goodsId) { //$goodsId = $this->request->param('goodsId', 0); $goodsId = intval($goodsId); if (empty($goodsId)) { return \redirect('index'); } $key = $this->request->param('key', ''); $goodsModel = new GoodsModel(); $goods = $goodsModel->getDetails($goodsId); if (empty($goods) || (isset($goods['status']) && $goods['status'] == 500)) { return \view('/error'); } $goods = $goods->toArray(); $goods['content'] = html_entity_decode($goods['content']); empty($goods['selling_point']) && $goods['selling_point'] = '0'; $model = new CommentModel; $total = $model->rowsTotal($goodsId); $goodsCategory = GoodsCategoryRel::where(['goods_id' => $goods['goods_id']])->find()->toArray(); $is_lost_mary = 0; if ($goodsCategory['category_id'] == GoodsCategoryRel::LOST_MARY_5000) { $is_lost_mary = 1; } $flavors = ['STRAWBERRY-MANGO', 'BLUE RAZZ-ICE', 'WATERMELON', 'GRAPE', 'KIWI-PASSION-FRUIT-GUAVA', 'JUICY-PEACH', 'BLUEBERRY-ICE']; return view('productDetails', ['goods' => $goods, 'comment_total' => $total, 'key' => $key, 'is_lost_mary' => $is_lost_mary]); } public function aboutUs(): View { return view('aboutUs'); } public function privacyPolicy(): View { return view('privacyPolicy'); } public function salesTerms(): View { return view('salesTerms'); } public function vapePoints(): View { return view('vapePoints'); } public function returnWarranty(): View { return view('returnWarranty'); } public function newsDetail($newsId): View { //$newsId = $this->request->param('newsId'); if (empty($newsId)) { return view('/error'); } $model = new ArticleModel; $article = $model->find($newsId)->toArray(); return view('newsDetails', ['article' => $article]); } public function goldTest() { $bjd = fopen("https://storage.googleapis.com/freeshippingvps/10001/20241010/5c046e98da7e1cd98ae0c42798357c0a.jpg","r"); dd($bjd); $filePath = public_path('10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg'); dd($filePath); $keyFilePath = '/etc/nginx/nginx/html/dihua-01-5690813badec.json'; $storage = new StorageClient(['projectId' => 'dihua-01', 'keyFilePath' => $keyFilePath]); $bucket = $storage->bucket('freeshippingvps'); $filePath = '/etc/nginx/nginx/html/vape_shop/public/uploads/10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg'; $storageObj = $bucket->upload( fopen($filePath, 'r'), [ 'name' => '10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg' //'predefinedAcl' => 'publicRead' ] ); $name = $storageObj->name(); return $this->renderSuccess(['name' => $name], 'OK'); $ip = $this->request->ip(); //$b = bcmod(1, 0); Log::debug($ip); Log::info('888'); Log::error('xxx'); Log::notice($ip); return $this->renderSuccess([], 'OK'); dd($ip); $conf = config('paypal'); dd($conf['sandbox'], $conf['live']); dd('this is ' . $name); $service = new OrderGetYundanService(); $r = $service->orderCreateYundans($this->storeId); dd($r); $orderModel = new OrderModel(); $r = $orderModel->getUsableList(10001); dd($r->toArray()); $Usps = new Usps(); // 请求查询接口 $res = $Usps->getItdidaToken(); dd($res); } }