Index.php 8.3 KB

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