Index.php 8.6 KB

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