Index.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\enum\file\FileType as FileTypeEnum;
  4. use app\common\enum\Setting as SettingEnum;
  5. use app\common\library\express\Usps;
  6. use app\common\library\storage\Driver as StorageDriver;
  7. use app\console\model\Order as OrderModel;
  8. use app\console\service\OrderGetYundan as OrderGetYundanService;
  9. use app\index\model\Article as ArticleModel;
  10. use app\index\model\Comment as CommentModel;
  11. use app\index\model\Goods as GoodsModel;
  12. use app\index\model\GoodsCategoryRel;
  13. use app\index\model\user\UserAccessLog;
  14. use app\store\model\Setting as SettingModel;
  15. use app\store\model\UploadFile as UploadFileModel;
  16. use Exception;
  17. use think\facade\Cache;
  18. use think\facade\Log;
  19. use think\facade\Session;
  20. use think\response\View;
  21. use Google\Cloud\Storage\StorageClient;
  22. /**
  23. * 默认控制器
  24. * Class Index
  25. * @package app\api\controller
  26. */
  27. class Index extends Controller
  28. {
  29. public function index()
  30. {
  31. //banner位
  32. $newArrivalCache = Cache::get('index_newArrival');
  33. $bestsellerCache = Cache::get('index_bestseller');
  34. $superDealsCache = Cache::get('index_superDeals');
  35. $articleCache = Cache::get('index_article');
  36. if ($newArrivalCache && $bestsellerCache && $superDealsCache && $articleCache) {
  37. $newArrival = json_decode($newArrivalCache, true);
  38. $bestseller = json_decode($bestsellerCache, true);
  39. $superDeals = json_decode($superDealsCache, true);
  40. $article = json_decode($articleCache, true);
  41. } else {
  42. //商品区。new,video,bestseller
  43. $model = new GoodsModel;
  44. $newArrival = $model->getList(['listType' => 'on_sale'], 8)->toArray()['data'];
  45. $bestseller = $model->getList(['sortType' => 'sales'], 8)->toArray()['data'];
  46. //$superDeals = $model->getList(['categoryId' => '10002',], 8)->toArray()['data'];
  47. $superDeals = $bestseller;
  48. $newGoodsId = array_column($newArrival, 'goods_id');
  49. $bestGoodsId = array_column($bestseller, 'goods_id');
  50. $superDealsGoodsId = array_column($superDeals, 'goods_id');
  51. //获取评价数量
  52. $goodsIds = array_unique(array_merge($newGoodsId, $bestGoodsId, $superDealsGoodsId));
  53. $commentModel = new CommentModel();
  54. $rows = $commentModel->rowsTotalBatch($goodsIds)->toArray();
  55. $rowsByGoodsId = array_column($rows, 'cnt', 'goods_id');
  56. //获取评论分数
  57. $commentScores = $commentModel->getTotalAll($goodsIds)->toArray();
  58. $scoresByGoodsId = array_column($commentScores, 'score_total', 'goods_id');
  59. //dd($rowsByGoodsId);
  60. //可考虑缓存
  61. foreach ($newArrival as &$item) {
  62. $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
  63. $temp = bcmul($item['comment_cnt'], 10, 0);
  64. if ($temp) {
  65. $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
  66. } else {
  67. $item['avg_score'] = 5;
  68. }
  69. }
  70. Cache::set('index_newArrival', json_encode($newArrival), 1200);
  71. foreach ($bestseller as &$item) {
  72. $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
  73. $temp = bcmul($item['comment_cnt'], 10, 0);
  74. if ($temp) {
  75. $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
  76. } else {
  77. $item['avg_score'] = 5;
  78. }
  79. }
  80. Cache::set('index_bestseller', json_encode($bestseller), 1200);
  81. foreach ($superDeals as &$item) {
  82. $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
  83. $temp = bcmul($item['comment_cnt'], 10, 0);
  84. if ($temp) {
  85. $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
  86. } else {
  87. $item['avg_score'] = 5;
  88. }
  89. }
  90. Cache::set('index_superDeals', json_encode($superDeals), 1200);
  91. $model = new ArticleModel;
  92. $article = $model->getList(0, 5)->toArray()['data'];
  93. foreach ($article as &$datum) {
  94. $datum['year'] = substr($datum['create_time'], 0, 4);
  95. $datum['month_day'] = substr($datum['create_time'], 5, 5);
  96. $datum['date'] = substr($datum['create_time'], 0, 10);
  97. }
  98. Cache::set('index_article', json_encode($article), 1200);
  99. }
  100. $superDeals1 = $superDeals2 = [];
  101. isset($superDeals[0]) && $superDeals1[] = $superDeals[0];
  102. isset($superDeals[1]) && $superDeals1[] = $superDeals[1];
  103. isset($superDeals[2]) && $superDeals1[] = $superDeals[2];
  104. isset($superDeals[3]) && $superDeals1[] = $superDeals[3];
  105. isset($superDeals[4]) && $superDeals2[] = $superDeals[4];
  106. isset($superDeals[5]) && $superDeals2[] = $superDeals[5];
  107. isset($superDeals[6]) && $superDeals2[] = $superDeals[6];
  108. isset($superDeals[7]) && $superDeals2[] = $superDeals[7];
  109. return view('/index/index', [
  110. 'newGoods' => $newArrival,
  111. 'bestseller' => $bestseller,
  112. 'superDealsOne' => $superDeals1,
  113. 'superDealsTwo' => $superDeals2,
  114. 'article' => $article,
  115. ]);
  116. }
  117. /**
  118. * 产品详情页
  119. * @return \think\response\Redirect|View
  120. * @throws \cores\exception\BaseException
  121. * @throws \think\db\exception\DataNotFoundException
  122. * @throws \think\db\exception\DbException
  123. * @throws \think\db\exception\ModelNotFoundException
  124. */
  125. public function productDetails($goodsId)
  126. {
  127. //$goodsId = $this->request->param('goodsId', 0);
  128. $goodsId = intval($goodsId);
  129. if (empty($goodsId)) {
  130. return \redirect('index');
  131. }
  132. $key = $this->request->param('key', '');
  133. $goodsModel = new GoodsModel();
  134. $goods = $goodsModel->getDetails($goodsId);
  135. if (empty($goods) || (isset($goods['status']) && $goods['status'] == 500)) {
  136. return \view('/error');
  137. }
  138. $goods = $goods->toArray();
  139. $goods['content'] = html_entity_decode($goods['content']);
  140. empty($goods['selling_point']) && $goods['selling_point'] = '0';
  141. $model = new CommentModel;
  142. $total = $model->rowsTotal($goodsId);
  143. $goodsCategory = GoodsCategoryRel::where(['goods_id' => $goods['goods_id']])->find()->toArray();
  144. $is_lost_mary = 0;
  145. if ($goodsCategory['category_id'] == GoodsCategoryRel::LOST_MARY_5000) {
  146. $is_lost_mary = 1;
  147. }
  148. $flavors = ['STRAWBERRY-MANGO', 'BLUE RAZZ-ICE', 'WATERMELON', 'GRAPE', 'KIWI-PASSION-FRUIT-GUAVA', 'JUICY-PEACH', 'BLUEBERRY-ICE'];
  149. return view('productDetails', ['goods' => $goods, 'comment_total' => $total, 'key' => $key, 'is_lost_mary' => $is_lost_mary]);
  150. }
  151. public function aboutUs(): View
  152. {
  153. return view('aboutUs');
  154. }
  155. public function privacyPolicy(): View
  156. {
  157. return view('privacyPolicy');
  158. }
  159. public function salesTerms(): View
  160. {
  161. return view('salesTerms');
  162. }
  163. public function vapePoints(): View
  164. {
  165. return view('vapePoints');
  166. }
  167. public function returnWarranty(): View
  168. {
  169. return view('returnWarranty');
  170. }
  171. public function newsDetail($newsId): View
  172. {
  173. //$newsId = $this->request->param('newsId');
  174. if (empty($newsId)) {
  175. return view('/error');
  176. }
  177. $model = new ArticleModel;
  178. $article = $model->find($newsId)->toArray();
  179. return view('newsDetails', ['article' => $article]);
  180. }
  181. public function goldTest()
  182. {
  183. dd(public_path());
  184. $fileInfo['file_path'] = '10001/20241014/9dedcf80308af9dbdd12515d259483ce.png';
  185. $sourceFile = 'D:\phpstudy_pro\WWW\gors\vape_shop\public\uploads/' . $fileInfo['file_path'];
  186. list($storeId,$date,$fileName) = explode('/' , $fileInfo['file_path']);
  187. $thumbnailFile = $storeId.'/'.$date.'/TH'.$fileName;// 缩略图保存路径
  188. // 使用示例
  189. try {
  190. $thumbnailFile = 'thumbnail.png'; // 缩略图保存路径
  191. createThumbnail($sourceFile, $thumbnailFile, 100, 80); // 创建缩略图
  192. } catch (Exception $e) {
  193. Log::error($e->getMessage());
  194. return $this->renderError($e->getMessage());
  195. }
  196. dd('haole');
  197. $bjd = fopen("https://storage.googleapis.com/freeshippingvps/10001/20241010/5c046e98da7e1cd98ae0c42798357c0a.jpg","r");
  198. dd($bjd);
  199. $filePath = public_path('10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg');
  200. dd($filePath);
  201. $keyFilePath = '/etc/nginx/nginx/html/dihua-01-5690813badec.json';
  202. $storage = new StorageClient(['projectId' => 'dihua-01', 'keyFilePath' => $keyFilePath]);
  203. $bucket = $storage->bucket('freeshippingvps');
  204. $filePath = '/etc/nginx/nginx/html/vape_shop/public/uploads/10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg';
  205. $storageObj = $bucket->upload(
  206. fopen($filePath, 'r'),
  207. [
  208. 'name' => '10001/20240618/24c7b239666052544c6a0a70489f58b6.jpg'
  209. //'predefinedAcl' => 'publicRead'
  210. ]
  211. );
  212. $name = $storageObj->name();
  213. return $this->renderSuccess(['name' => $name], 'OK');
  214. $ip = $this->request->ip();
  215. //$b = bcmod(1, 0);
  216. Log::debug($ip);
  217. Log::info('888');
  218. Log::error('xxx');
  219. Log::notice($ip);
  220. return $this->renderSuccess([], 'OK');
  221. dd($ip);
  222. $conf = config('paypal');
  223. dd($conf['sandbox'], $conf['live']);
  224. dd('this is ' . $name);
  225. $service = new OrderGetYundanService();
  226. $r = $service->orderCreateYundans($this->storeId);
  227. dd($r);
  228. $orderModel = new OrderModel();
  229. $r = $orderModel->getUsableList(10001);
  230. dd($r->toArray());
  231. $Usps = new Usps();
  232. // 请求查询接口
  233. $res = $Usps->getItdidaToken();
  234. dd($res);
  235. }
  236. }