Index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\enum\file\FileType as FileTypeEnum;
  4. use app\common\enum\Setting as SettingEnum;
  5. use app\common\library\express\Usps;
  6. use app\common\library\storage\Driver as StorageDriver;
  7. use app\console\model\Order as OrderModel;
  8. use app\console\service\OrderGetYundan as OrderGetYundanService;
  9. use app\index\model\Article as ArticleModel;
  10. use app\index\model\Comment as CommentModel;
  11. use app\index\model\Goods as GoodsModel;
  12. use app\index\model\GoodsCategoryRel;
  13. use app\index\model\user\UserAccessLog;
  14. use app\store\model\Setting as SettingModel;
  15. use app\store\model\UploadFile as UploadFileModel;
  16. use think\facade\Cache;
  17. use think\facade\Log;
  18. use think\facade\Session;
  19. use think\response\View;
  20. use Google\Cloud\Storage\StorageClient;
  21. /**
  22. * 默认控制器
  23. * Class Index
  24. * @package app\api\controller
  25. */
  26. class Index extends Controller
  27. {
  28. public function index()
  29. {
  30. //banner位
  31. $newArrivalCache = Cache::get('index_newArrival');
  32. $bestsellerCache = Cache::get('index_bestseller');
  33. $superDealsCache = Cache::get('index_superDeals');
  34. $articleCache = Cache::get('index_article');
  35. if ($newArrivalCache && $bestsellerCache && $superDealsCache && $articleCache) {
  36. $newArrival = json_decode($newArrivalCache, true);
  37. $bestseller = json_decode($bestsellerCache, true);
  38. $superDeals = json_decode($superDealsCache, true);
  39. $article = json_decode($articleCache, true);
  40. } else {
  41. //商品区。new,video,bestseller
  42. $model = new GoodsModel;
  43. $newArrival = $model->getList(['listType' => 'on_sale'], 8)->toArray()['data'];
  44. $bestseller = $model->getList(['sortType' => 'sales'], 8)->toArray()['data'];
  45. //$superDeals = $model->getList(['categoryId' => '10002',], 8)->toArray()['data'];
  46. $superDeals = $bestseller;
  47. $newGoodsId = array_column($newArrival, 'goods_id');
  48. $bestGoodsId = array_column($bestseller, 'goods_id');
  49. $superDealsGoodsId = array_column($superDeals, 'goods_id');
  50. //获取评价数量
  51. $goodsIds = array_unique(array_merge($newGoodsId, $bestGoodsId, $superDealsGoodsId));
  52. $commentModel = new CommentModel();
  53. $rows = $commentModel->rowsTotalBatch($goodsIds)->toArray();
  54. $rowsByGoodsId = array_column($rows, 'cnt', 'goods_id');
  55. //获取评论分数
  56. $commentScores = $commentModel->getTotalAll($goodsIds)->toArray();
  57. $scoresByGoodsId = array_column($commentScores, 'score_total', 'goods_id');
  58. //dd($rowsByGoodsId);
  59. //可考虑缓存
  60. foreach ($newArrival as &$item) {
  61. $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
  62. $temp = bcmul($item['comment_cnt'], 10, 0);
  63. if ($temp) {
  64. $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
  65. } else {
  66. $item['avg_score'] = 5;
  67. }
  68. }
  69. Cache::set('index_newArrival', json_encode($newArrival), 1200);
  70. foreach ($bestseller as &$item) {
  71. $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
  72. $temp = bcmul($item['comment_cnt'], 10, 0);
  73. if ($temp) {
  74. $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
  75. } else {
  76. $item['avg_score'] = 5;
  77. }
  78. }
  79. Cache::set('index_bestseller', json_encode($bestseller), 1200);
  80. foreach ($superDeals as &$item) {
  81. $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
  82. $temp = bcmul($item['comment_cnt'], 10, 0);
  83. if ($temp) {
  84. $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
  85. } else {
  86. $item['avg_score'] = 5;
  87. }
  88. }
  89. Cache::set('index_superDeals', json_encode($superDeals), 1200);
  90. $model = new ArticleModel;
  91. $article = $model->getList(0, 5)->toArray()['data'];
  92. foreach ($article as &$datum) {
  93. $datum['year'] = substr($datum['create_time'], 0, 4);
  94. $datum['month_day'] = substr($datum['create_time'], 5, 5);
  95. $datum['date'] = substr($datum['create_time'], 0, 10);
  96. }
  97. Cache::set('index_article', json_encode($article), 1200);
  98. }
  99. $superDeals1 = $superDeals2 = [];
  100. isset($superDeals[0]) && $superDeals1[] = $superDeals[0];
  101. isset($superDeals[1]) && $superDeals1[] = $superDeals[1];
  102. isset($superDeals[2]) && $superDeals1[] = $superDeals[2];
  103. isset($superDeals[3]) && $superDeals1[] = $superDeals[3];
  104. isset($superDeals[4]) && $superDeals2[] = $superDeals[4];
  105. isset($superDeals[5]) && $superDeals2[] = $superDeals[5];
  106. isset($superDeals[6]) && $superDeals2[] = $superDeals[6];
  107. isset($superDeals[7]) && $superDeals2[] = $superDeals[7];
  108. return view('/index/index', [
  109. 'newGoods' => $newArrival,
  110. 'bestseller' => $bestseller,
  111. 'superDealsOne' => $superDeals1,
  112. 'superDealsTwo' => $superDeals2,
  113. 'article' => $article,
  114. ]);
  115. }
  116. /**
  117. * 产品详情页
  118. * @return \think\response\Redirect|View
  119. * @throws \cores\exception\BaseException
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\DbException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. */
  124. public function productDetails($goodsId)
  125. {
  126. //$goodsId = $this->request->param('goodsId', 0);
  127. $goodsId = intval($goodsId);
  128. if (empty($goodsId)) {
  129. return \redirect('index');
  130. }
  131. $key = $this->request->param('key', '');
  132. $goodsModel = new GoodsModel();
  133. $goods = $goodsModel->getDetails($goodsId);
  134. if (empty($goods) || (isset($goods['status']) && $goods['status'] == 500)) {
  135. return \view('/error');
  136. }
  137. $goods = $goods->toArray();
  138. $goods['content'] = html_entity_decode($goods['content']);
  139. empty($goods['selling_point']) && $goods['selling_point'] = '0';
  140. $model = new CommentModel;
  141. $total = $model->rowsTotal($goodsId);
  142. $goodsCategory = GoodsCategoryRel::where(['goods_id' => $goods['goods_id']])->find()->toArray();
  143. $is_lost_mary = 0;
  144. if ($goodsCategory['category_id'] == GoodsCategoryRel::LOST_MARY_5000) {
  145. $is_lost_mary = 1;
  146. }
  147. $flavors = ['STRAWBERRY-MANGO', 'BLUE RAZZ-ICE', 'WATERMELON', 'GRAPE', 'KIWI-PASSION-FRUIT-GUAVA', 'JUICY-PEACH', 'BLUEBERRY-ICE'];
  148. return view('productDetails', ['goods' => $goods, 'comment_total' => $total, 'key' => $key, 'is_lost_mary' => $is_lost_mary]);
  149. }
  150. public function aboutUs(): View
  151. {
  152. return view('aboutUs');
  153. }
  154. public function privacyPolicy(): View
  155. {
  156. return view('privacyPolicy');
  157. }
  158. public function salesTerms(): View
  159. {
  160. return view('salesTerms');
  161. }
  162. public function vapePoints(): View
  163. {
  164. return view('vapePoints');
  165. }
  166. public function returnWarranty(): View
  167. {
  168. return view('returnWarranty');
  169. }
  170. public function newsDetail($newsId): View
  171. {
  172. //$newsId = $this->request->param('newsId');
  173. if (empty($newsId)) {
  174. return view('/error');
  175. }
  176. $model = new ArticleModel;
  177. $article = $model->find($newsId)->toArray();
  178. return view('newsDetails', ['article' => $article]);
  179. }
  180. public function goldTest()
  181. {
  182. $bjd = fopen("https://storage.googleapis.com/freeshippingvps/10001/20241010/5c046e98da7e1cd98ae0c42798357c0a.jpg","r");
  183. dd($bjd);
  184. $filePath = public_path('10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg');
  185. dd($filePath);
  186. $keyFilePath = '/etc/nginx/nginx/html/dihua-01-5690813badec.json';
  187. $storage = new StorageClient(['projectId' => 'dihua-01', 'keyFilePath' => $keyFilePath]);
  188. $bucket = $storage->bucket('freeshippingvps');
  189. $filePath = '/etc/nginx/nginx/html/vape_shop/public/uploads/10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg';
  190. $storageObj = $bucket->upload(
  191. fopen($filePath, 'r'),
  192. [
  193. 'name' => '10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg'
  194. //'predefinedAcl' => 'publicRead'
  195. ]
  196. );
  197. $name = $storageObj->name();
  198. return $this->renderSuccess(['name' => $name], 'OK');
  199. $ip = $this->request->ip();
  200. //$b = bcmod(1, 0);
  201. Log::debug($ip);
  202. Log::info('888');
  203. Log::error('xxx');
  204. Log::notice($ip);
  205. return $this->renderSuccess([], 'OK');
  206. dd($ip);
  207. $conf = config('paypal');
  208. dd($conf['sandbox'], $conf['live']);
  209. dd('this is ' . $name);
  210. $service = new OrderGetYundanService();
  211. $r = $service->orderCreateYundans($this->storeId);
  212. dd($r);
  213. $orderModel = new OrderModel();
  214. $r = $orderModel->getUsableList(10001);
  215. dd($r->toArray());
  216. $Usps = new Usps();
  217. // 请求查询接口
  218. $res = $Usps->getItdidaToken();
  219. dd($res);
  220. }
  221. }