Index.php 7.6 KB

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