Index.php 8.1 KB

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