Index.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. $goodsId = intval($goodsId);
  121. if (empty($goodsId)) {
  122. return \redirect('index');
  123. }
  124. $key = $this->request->param('key', '');
  125. $goodsModel = new GoodsModel();
  126. $goods = $goodsModel->getDetails($goodsId);
  127. if (empty($goods) || (isset($goods['status']) && $goods['status'] == 500)){
  128. return \view('/error');
  129. }
  130. $goods = $goods->toArray();
  131. $goods['content'] = html_entity_decode($goods['content']);
  132. $model = new CommentModel;
  133. $total = $model->rowsTotal($goodsId);
  134. $flavors = ['STRAWBERRY-MANGO', 'BLUE RAZZ-ICE', 'WATERMELON', 'GRAPE', 'KIWI-PASSION-FRUIT-GUAVA', 'JUICY-PEACH', 'BLUEBERRY-ICE'];
  135. return view('productDetails', ['goods' => $goods, 'comment_total' => $total, 'key' => $key]);
  136. }
  137. public function aboutUs(): View
  138. {
  139. return view('aboutUs');
  140. }
  141. public function privacyPolicy(): View
  142. {
  143. return view('privacyPolicy');
  144. }
  145. public function salesTerms(): View
  146. {
  147. return view('salesTerms');
  148. }
  149. public function vapePoints(): View
  150. {
  151. return view('vapePoints');
  152. }
  153. public function returnWarranty(): View
  154. {
  155. return view('returnWarranty');
  156. }
  157. public function newsDetail($newsId): View
  158. {
  159. //$newsId = $this->request->param('newsId');
  160. if (empty($newsId)) {
  161. return view('/error');
  162. }
  163. $model = new ArticleModel;
  164. $article = $model->find($newsId)->toArray();
  165. return view('newsDetails', ['article' => $article]);
  166. }
  167. public function goldTest($name)
  168. {
  169. $ip = $this->request->ip();
  170. //$b = bcmod(1, 0);
  171. Log::debug($ip);
  172. Log::info('888');
  173. Log::error('xxx');
  174. Log::notice($ip);
  175. return $this->renderSuccess([],'OK');
  176. dd($ip);
  177. $conf = config('paypal');
  178. dd($conf['sandbox'], $conf['live']);
  179. dd('this is ' . $name);
  180. $service = new OrderGetYundanService();
  181. $r = $service->orderCreateYundans($this->storeId);
  182. dd($r);
  183. $orderModel = new OrderModel();
  184. $r = $orderModel->getUsableList(10001);
  185. dd($r->toArray());
  186. $Usps = new Usps();
  187. // 请求查询接口
  188. $res = $Usps->getItdidaToken();
  189. dd($res);
  190. }
  191. }