User.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\enum\order\PayStatus;
  4. use app\index\model\Goods;
  5. use app\index\model\ShareKey;
  6. use app\index\service\passport\MailCaptcha as MailCaptchaService;
  7. use app\index\model\OrderAddress;
  8. use app\index\model\user\PointsLog as PointsLogModel;
  9. use app\index\model\Goods as GoodsModel;
  10. use app\index\model\Order as OrderModel;
  11. use app\store\model\Express as ExpressModel;
  12. use think\facade\Cache;
  13. use think\facade\Log;
  14. use think\facade\Session;
  15. /**
  16. * 默认控制器
  17. * Class User
  18. * @package app\api\controller
  19. */
  20. class User extends Controller
  21. {
  22. /**
  23. * 个人中心
  24. * @return \think\response\View
  25. */
  26. public function personal()
  27. {
  28. $userId = Session::get('user_id');
  29. if (empty($userId)) {
  30. return view('passport/logIn');
  31. }
  32. $goodsModel = new GoodsModel();
  33. //$goods['content'] = html_entity_decode($goods['content']);
  34. return view('order', ['goods' => []]);
  35. }
  36. /**
  37. * 我的订单页面
  38. * @return \think\response\View
  39. */
  40. public function order(string $orderType = 'received')
  41. {
  42. $userId = Session::get('user_id');
  43. if (empty($userId)) {
  44. Cache::set('returnuri', '/index/user/order.html', 300);
  45. return view('passport/logIn');
  46. }
  47. return view('order');
  48. }
  49. /**
  50. * 订单详情
  51. * @param $orderId
  52. * @return \think\response\View
  53. * @throws \cores\exception\BaseException
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function orderDetails($orderId)
  59. {
  60. $orderId = intval($orderId);
  61. $userId = Session::get('user_id');
  62. if (empty($userId)) {
  63. Cache::set('returnuri', '/index/user/orderDetails.html?orderId=' . $orderId, 300);
  64. return view('passport/logIn');
  65. }
  66. $model = OrderModel::getUserOrderDetail($orderId);
  67. $orderAddress = OrderAddress::get(['order_id' => $orderId]);
  68. if (!empty($model['express_no'])) {
  69. $expModel = new ExpressModel();
  70. $tracks = $expModel->dynamicUsps($model['express_no']);
  71. //dd($tracks);
  72. } else {
  73. $tracks = [];
  74. }
  75. if (!$tracks) {
  76. $f1Track = [];
  77. } else {
  78. $f1Track = $tracks['list'][0]['trackList'] ?? [];
  79. }
  80. $createTimeInt = strtotime($model['create_time']);
  81. $selfTrack = [];
  82. if (time() > $createTimeInt + 9864) {
  83. $selfTrack[] = ['time' => date('Y-m-d H:i:s', $createTimeInt + 9864), 'text' => 'Orders taken', 'desc' => 'The order has entered the warehouse'];
  84. }
  85. if (time() > $createTimeInt + 3653) {
  86. $selfTrack[] = ['time' => date('Y-m-d H:i:s', $createTimeInt + 3653), 'text' => 'Orders taken', 'desc' => 'The merchant has received your order and is waiting to be shipped'];
  87. }
  88. if ($model['pay_status'] == PayStatus::SUCCESS) {
  89. $selfTrack[] = ['time' => date('Y-m-d H:i:s', $createTimeInt + 5), 'text' => 'Order paid', 'desc' => 'Successful'];
  90. }
  91. return view('orderDetails', ['order' => $model, 'orderAddress' => $orderAddress, 'selfTrack' => $selfTrack, 'f1Track' => $f1Track]);
  92. }
  93. /**
  94. * 我的积分页面
  95. * @return \think\response\View
  96. */
  97. public function myScores()
  98. {
  99. $userId = Session::get('user_id');
  100. if (empty($userId)) {
  101. return view('passport/logIn');
  102. }
  103. $model = new PointsLogModel;
  104. $list = $model->getList();
  105. $user = \app\index\service\User::getCurrentLoginUser();
  106. return view('integral', ['user' => $user]);
  107. }
  108. /**
  109. * 我的积分列表
  110. * @return \think\response\Json
  111. * @throws \app\common\exception\BaseException
  112. * @throws \think\db\exception\DbException
  113. */
  114. public function pointsLogs()
  115. {
  116. $model = new PointsLogModel;
  117. $list = $model->getList();
  118. return $this->renderSuccess(compact('list'));
  119. }
  120. /**
  121. * 分享商品
  122. * @return \think\response\Json
  123. */
  124. public function shareUser()
  125. {
  126. $userId = Session::get('user_id');
  127. if (empty($userId)) {
  128. return $this->renderJson(config('status.not_logged'), 'Log in please!');
  129. }
  130. $goodsId = $this->request->param('goodsId');
  131. if (empty($goodsId)) {
  132. return $this->renderError('Invalid goods');
  133. }
  134. $mailbox = $this->request->param('mailbox');
  135. if (empty($mailbox)) {
  136. return $this->renderError('Invalid mailbox');
  137. }
  138. $encryptUserId = encrypt(strval($userId));
  139. $url = 'Your friend shared a product with you. Click on the link to view it now:'
  140. . config('app.app_host') . '/index/index/productDetails.html?goodsId=' . $goodsId . '&key=' . $encryptUserId;
  141. Log::info($url);
  142. $MailCaptchaService = new MailCaptchaService;
  143. if ($MailCaptchaService->sendText($mailbox, 'From Your Friend', $url)) {
  144. $shareKeyModel = new ShareKey();
  145. $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
  146. return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
  147. }
  148. if (is_debug()) {
  149. $shareKeyModel = new ShareKey();
  150. $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
  151. }
  152. return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
  153. }
  154. /**
  155. * 生成马甲号
  156. * @return \think\response\Json
  157. * @throws \Exception
  158. */
  159. public function genFakeUsers()
  160. {
  161. $names = ['Eliana',
  162. 'Elias',
  163. 'Brooklyn',
  164. 'Joshua',
  165. 'Elena',
  166. 'Nathan',
  167. 'Aubrey',
  168. 'Caleb',
  169. 'Claire',
  170. 'Ryan',
  171. 'Ivy',
  172. 'Adrian',
  173. 'Kinsley',
  174. 'Miles',
  175. 'Audrey',
  176. 'Eli',
  177. 'Maya',
  178. 'Nolan',
  179. 'Genesis',
  180. 'Christian',
  181. 'Skylar',
  182. 'Aaron',
  183. 'Bella',
  184. 'Cameron',
  185. 'Aaliyah',
  186. 'Ezekiel',
  187. 'Madelyn',
  188. 'Colton',
  189. 'Savannah',
  190. 'Luca',
  191. 'Anna',
  192. 'Landon',
  193. 'Delilah',
  194. 'Hunter',
  195. 'Serenity',
  196. 'Jonathan',
  197. 'Caroline',
  198. 'Santiago',
  199. 'Kennedy',
  200. 'Axel',
  201. 'Valentina',
  202. 'Easton',
  203. 'Ruby',
  204. 'Cooper',
  205. 'Sophie',
  206. 'Jeremiah',
  207. 'Alice',
  208. 'Angel',
  209. 'Gabriella',
  210. 'Roman',
  211. 'Sadie',
  212. 'Connor',
  213. 'Ariana',
  214. 'Jameson',
  215. 'Allison',
  216. 'Robert',
  217. 'Hailey',
  218. 'Greyson',
  219. 'Autumn',
  220. 'Jordan',
  221. 'Nevaeh',
  222. 'Ian',
  223. 'Natalia',
  224. 'Carson',
  225. 'Quinn',
  226. 'Jaxson',
  227. 'Josephine',
  228. 'Leonardo',
  229. 'Sarah',
  230. 'Nicholas',
  231. 'Cora',
  232. 'Dominic',
  233. 'Emery',
  234. 'Austin',
  235. 'Samantha',
  236. 'Everett',
  237. 'Piper',
  238. 'Brooks',
  239. 'Leilani',
  240. 'Xavier',
  241. 'Eva',
  242. 'Kai',
  243. 'Everleigh',
  244. 'Jose',
  245. 'Madeline',
  246. 'Parker',
  247. 'Lydia',
  248. 'Adam',
  249. 'Jade',
  250. 'Jace',
  251. 'Peyton',
  252. 'Wesley',
  253. 'Brielle',
  254. 'Kayden',
  255. 'Adeline',
  256. 'Silas',
  257. 'Vivian',
  258. 'Bennett',
  259. 'Rylee',
  260. 'Declan',
  261. 'Clara',
  262. 'Waylon',
  263. 'Raelynn',
  264. 'Weston',
  265. 'Melanie',
  266. 'Evan',
  267. 'Melody',
  268. 'Emmett',
  269. 'Julia',
  270. 'Micah',
  271. 'Athena',
  272. 'Ryder',
  273. 'Maria',
  274. 'Beau',
  275. 'Liliana',
  276. 'Damian',
  277. 'Hadley',
  278. 'Hadley',
  279. 'Brayden',
  280. 'Arya',
  281. 'Gael',
  282. 'Rose',
  283. 'Rowan',
  284. 'Reagan',
  285. 'Harrison',
  286. 'Eliza',
  287. 'Bryson',
  288. 'Adalynn',
  289. 'Adalynn',
  290. 'Sawyer',
  291. 'Kaylee',
  292. 'Amir',
  293. 'Lyla',
  294. 'Kingston',
  295. 'Mackenzie',
  296. 'Jason',
  297. 'Alaia',
  298. 'Giovanni',
  299. 'Isabelle',
  300. 'Vincent',
  301. 'Charlie',
  302. 'Ayden',
  303. 'Arianna',
  304. 'Chase',
  305. 'Mary',
  306. 'Myles',
  307. 'Myles',
  308. 'Remi',
  309. 'Diego',
  310. 'Margaret',
  311. 'Nathaniel',
  312. 'Iris',
  313. 'Legend',
  314. 'Parker',
  315. 'Jonah',
  316. 'Ximena',
  317. 'River',
  318. 'Eden',
  319. 'Tyler',
  320. 'Ayla',
  321. 'Cole',
  322. 'Kylie',
  323. 'Braxton',
  324. 'Elliana',
  325. 'George',
  326. 'Josie',
  327. 'Milo',
  328. 'Katherine',
  329. 'Zachary',
  330. 'Faith',
  331. 'Ashton',
  332. 'Alexandra',
  333. 'Luis',
  334. 'Eloise',
  335. 'Jasper',
  336. 'Adalyn',
  337. 'Adalyn',
  338. 'Kaiden',
  339. 'Amaya',
  340. 'Adriel',
  341. 'Jasmine',
  342. 'Gavin',
  343. 'Amara',
  344. 'Bentley',
  345. 'Daisy',
  346. 'Calvin',
  347. 'Reese',
  348. 'Zion',
  349. 'Valerie',
  350. 'Juan',
  351. 'Brianna',
  352. 'Maxwell',
  353. 'Cecilia',
  354. 'Max',
  355. 'Andrea',
  356. 'Ryker',
  357. 'Summer',
  358. 'Carlos',
  359. 'Valeria',
  360. 'Emmanuel',
  361. 'Norah',
  362. 'Jayce',
  363. 'Ariella',
  364. 'Lorenzo',
  365. 'Esther',
  366. 'Ivan',
  367. 'Ashley',
  368. 'Jude',
  369. 'Emerson',
  370. 'August',
  371. 'August',
  372. 'Aubree',
  373. 'Kevin',
  374. 'Isabel',
  375. 'Malachi',
  376. 'Anastasia',
  377. 'Elliott',
  378. 'Genevieve',
  379. 'Jesus',
  380. 'Alina',
  381. 'Maddox',
  382. 'Bailey',
  383. 'King',
  384. 'Juniper',
  385. 'Theo',
  386. 'Maeve'];
  387. $salt = 'xxxxxx';
  388. $password = md5('123456' . $salt);
  389. for ($i = 0; $i < 100; $i++) {
  390. $user = [];
  391. $temp = $names[rand(0, 225)] . '_' . rand(100000, 999999);
  392. $user['mobile'] = $temp . '@fvp.com';
  393. $user['nick_name'] = $temp;
  394. $user['avatar_id'] = 0;
  395. $user['gender'] = 1;
  396. $user['country'] = 'US';
  397. $user['province'] = '';
  398. $user['city'] = '';
  399. $user['address_id'] = 0;
  400. $user['balance'] = 0;
  401. $user['points'] = 0;
  402. $user['pay_money'] = 0;
  403. $user['expend_money'] = 0;
  404. $user['platform'] = 'h5';
  405. $user['last_login_time'] = time();
  406. $user['is_delete'] = 0;
  407. $user['store_id'] = 10001;
  408. $user['create_time'] = time();
  409. $user['update_time'] = time();
  410. $user['salt'] = $salt;
  411. $user['password'] = $password;
  412. $users[] = $user;
  413. }
  414. $userModel = new \app\index\model\User();
  415. $userModel->saveAll($users);
  416. return $this->renderSuccess([], 'Successful!');
  417. }
  418. /**
  419. * 评论生成器
  420. * @return \think\response\Json
  421. * @throws \Exception
  422. */
  423. public function genGoodsComments()
  424. {
  425. //113
  426. $favor = [
  427. 'very realistic',
  428. 'I no longer have to worry about not finding an ashtray.',
  429. 'very portable',
  430. 'tastes very good',
  431. 'like fresh strawberries',
  432. 'refreshing but not overwhelming',
  433. 'very refreshing',
  434. 'tastes like enjoying a cup of hot cocoa',
  435. 'completely different from the bitterness and throat irritation of traditional cigarettes',
  436. 'different favor',
  437. "Tastes like enjoying a cup of hot cocoa, warm and delightful.",
  438. "addictive!",
  439. "Feels like biting into a fresh apple, crisp and delicious.",
  440. "There's a subtle vanilla flavor, making you feel like you're in a garden.",
  441. "Tastes like caramel with a delicate sweetness.",
  442. "It feels like savoring the aroma of freshly baked bread, absolutely tantalizing.",
  443. "Tastes like sipping on a tangy-sweet lemonade.",
  444. "There's a refreshing oceanic taste, making you feel like you're on the beach.",
  445. "The taste of this electronic product is like fresh grass, uplifting.",
  446. "It feels like tasting the richness of coffee.",
  447. "Feels like indulging in a mouthful of creamy ice cream, smooth and delicious.",
  448. "Tastes a bit like smelling a bouquet of fresh roses.",
  449. "Feels like tasting the aroma of freshly baked bread.",
  450. "There's a rich chocolate flavor, making you feel like you're in heaven.",
  451. "The taste of this electronic product is like a fresh fruit platter, delightful in every way.",
  452. "The taste is like savoring a mouthful of sweet honey.",
  453. "Feels like enjoying a cup of mild tea, warm and comforting.",
  454. "Tastes like indulging in a sweet and chilled fruit juice.",
  455. "There's a refreshing herbal taste, making you feel refreshed.",
  456. "Feels like savoring a cup of rich Italian coffee, strong and aromatic.",
  457. "The taste is like enjoying a dense chocolate cake.",
  458. "Feels like being surrounded by the scent of flowers in a garden.",
  459. "Tastes a bit like biting into a fresh watermelon, sweet and juicy.",
  460. "There's a cool minty flavor, instantly refreshing.",
  461. "Feels like savoring a cup of aromatic latte, full of vitality.",
  462. "Tastes like indulging in a sweet marshmallow.",
  463. "Feels like enjoying a tangy-sweet lemon tea.",
  464. "Tastes a bit like sipping on a fresh coconut water, sweet and refreshing.",
  465. "There's a subtle vanilla flavor, uplifting the mood.",
  466. "Feels like savoring a rich chocolate cake, delicious and delightful.",
  467. "Tastes like enjoying a cool scoop of ice cream.",
  468. "Feels like being surrounded by the scent of fresh flowers.",
  469. "Tastes a bit like indulging in a scoop of fresh strawberry ice cream.",
  470. "There's a rich coffee flavor, making you feel energetic.",
  471. "Feels like savoring a cup of steaming hot black tea, warm and comforting.",
  472. "Tastes like indulging in a rich chocolate cake.",
  473. "Feels like enjoying a cup of sweet coconut milkshake.",
  474. "Tastes a bit like savoring a fresh blueberry ice cream.",
  475. "There's a subtle herbal taste, making you feel connected to nature.",
  476. "Feels like savoring a cup of aromatic mocha coffee, with fragrance filling the air.",
  477. "Tastes like enjoying a smooth scoop of mango ice cream.",
  478. "Feels like bathing in the refreshing scent of oranges.",
  479. "Tastes a bit like indulging in a sweet fruit salad.",
  480. 'very rich',
  481. 'So rich',
  482. 'Very delicate',
  483. 'So Delicate',
  484. 'Fresh',
  485. 'Pleasant',
  486. 'Refreshing',
  487. 'Robust',
  488. 'Aromatic',
  489. 'So Clean',
  490. 'Clean',
  491. 'Mild',
  492. 'Very Sweet',
  493. 'So Smooth',
  494. 'Mellow',
  495. 'Fragrant',
  496. 'So Warm',
  497. 'Intense',
  498. 'Light',
  499. 'Velvety',
  500. 'Deep',
  501. 'So deep',
  502. 'Satisfying',
  503. 'Subtle sweetness',
  504. 'Minty freshness',
  505. 'Luscious',
  506. 'Sweet-tasting',
  507. 'Long-lasting aftertaste',
  508. 'Zesty',
  509. 'Pure',
  510. 'Very Pure',
  511. 'Silky',
  512. 'Very Silky',
  513. 'Fiery',
  514. 'Icy',
  515. 'Very Icy',
  516. 'Exquisite fragrance',
  517. 'Comforting',
  518. 'Honeyed',
  519. 'Strong',
  520. 'So Strong, I like it',
  521. 'Balanced acidity',
  522. 'Subtle',
  523. 'Silken',
  524. 'Smooth and mellow',
  525. 'Creamy',
  526. 'Rich flavor',
  527. 'Delicious',
  528. 'Richly fragrant',
  529. 'Comfortable',
  530. 'Tasty',
  531. 'Tasty good',
  532. 'Full-bodied',
  533. 'Fresh and invigorating',
  534. 'Refreshing',
  535. 'Pleasing to the palate',
  536. 'Crisp',
  537. 'Complex',
  538. 'Satisfying',
  539. 'very realistic',
  540. ];
  541. //50
  542. $price = [
  543. 'Affordable',
  544. 'Budget-friendly',
  545. 'Inexpensive',
  546. 'Economical',
  547. 'Cost-effective',
  548. 'Reasonably priced',
  549. 'Wallet-friendly',
  550. 'Cheap',
  551. 'Low-cost',
  552. 'Pocket-friendly',
  553. 'Bargain',
  554. 'Value for money',
  555. 'Dirt cheap',
  556. 'Cost-efficient',
  557. 'Discounted',
  558. 'Thrifty',
  559. 'Economically priced',
  560. 'Within budget',
  561. 'Modestly priced',
  562. 'Frugal',
  563. 'Low-priced',
  564. 'Marked down',
  565. 'Unbeatable price',
  566. 'Discounted rate',
  567. 'Value-priced',
  568. 'Competitive pricing',
  569. 'Affordable option',
  570. 'Great value',
  571. 'Rock-bottom prices',
  572. 'Cost-conscious',
  573. 'Sale price',
  574. 'Reasonable cost',
  575. 'Budget-conscious',
  576. 'Discount pricing',
  577. 'Low-priced option',
  578. 'Wallet-friendly choice',
  579. 'Entry-level pricing',
  580. 'Discounted deal',
  581. 'Cost-saving',
  582. 'Discounted rate',
  583. 'Sale bargain',
  584. 'Unmatched value',
  585. 'Unbelievably cheap',
  586. 'Steal deal',
  587. 'Slashed prices',
  588. 'Reduced rate',
  589. 'Great deal',
  590. 'Budget-friendly option',
  591. 'Money-saving',
  592. 'On a budget',
  593. ];
  594. //22
  595. $amount = ['the amount of smoke is very large',
  596. 'very large',
  597. 'On sale',
  598. 'Abundant',
  599. 'Plentiful',
  600. 'this vapor is plentiful',
  601. 'Ample',
  602. 'Copious',
  603. 'Generous',
  604. 'Generous vapor',
  605. 'Substantial',
  606. 'Bountiful',
  607. 'Overflowing',
  608. 'Profuse',
  609. 'Plenty',
  610. 'Rich in quantity',
  611. 'Prolific',
  612. 'Luxuriant',
  613. 'In abundance',
  614. 'good',
  615. 'my favorite',
  616. 'will buy again'
  617. ];
  618. /* $pool = [
  619. 'The taste of this e-cigarette is really great, completely different from the bitterness and throat irritation of traditional cigarettes.',
  620. 'The smoke effect of electronic cigarettes is very realistic, as if I can truly feel the pleasure of smoking, and the amount of smoke is very large, so I can enjoy the smoking experience for a long time.',
  621. 'After switching to e-cigarettes, I found that my body seemed to be healthier and there was no intake of harmful substances like traditional cigarettes. It was really great.',
  622. 'Electronic cigarettes are very environmentally friendly, do not produce smoke, and have no negative impact on the environment, which makes me feel very proud.',
  623. 'very portable', ' I can use them anytime, anywhere. They are very convenient, and I no longer have to worry about not finding an ashtray.'
  624. ];*/
  625. $goodsModel = new Goods();
  626. $goods = $goodsModel->getListSimple()->toArray();
  627. $score = [40, 50];
  628. //所有的马甲号userid
  629. $userModel = new \app\index\model\User();
  630. $userIds = $userModel->where('salt', 'xxxxxx')->column('user_id');
  631. $userNum = count($userIds);
  632. $now = time();
  633. $commentModel = new \app\index\model\Comment();
  634. foreach ($goods as $item) {
  635. $commentsNum = rand(30, 100);
  636. $comments = [];
  637. for ($i = 0; $i < $commentsNum; $i++) {
  638. $comment = [
  639. 'score' => $score[rand(0, 1)],
  640. 'content' => $favor[rand(0, 112)] . ', ' . $price[rand(0, 49)] . ', ' . $amount[rand(0, 21)],
  641. 'is_picture' => 0,
  642. 'status' => 1,
  643. 'sort' => rand(0, 99),
  644. 'user_id' => $userIds[rand(0, $userNum - 1)],
  645. 'order_id' => 0,
  646. 'goods_id' => $item['goods_id'],
  647. 'order_goods_id' => 0,
  648. 'store_id' => 10001,
  649. 'is_delete' => 0,
  650. 'create_time' => $now,
  651. 'update_time' => $now,
  652. ];
  653. $comments[] = $comment;
  654. }
  655. $commentModel->saveAll($comments);
  656. }
  657. return $this->renderSuccess([], 'Successful!');
  658. }
  659. public function genArticles()
  660. {
  661. $ecfHost = 'https://www.e-cigarette-forum.com';
  662. $f = file_get_contents('https://www.e-cigarette-forum.com/forums/e-cigarette-news.629/');
  663. //$f = '<div class="structItem-title" uix-href="/threads/will-not-stop-tobacco-control-unlikely-to-validate-nicotine-vaping-regwatch.983599/">';
  664. //帖子列表匹配
  665. $preg = '/<div\s+class="structItem-title"\s+uix-href="\/threads.+\/">/';
  666. $matches = [];
  667. preg_match_all($preg, $f, $matches);
  668. if (empty($matches[0])) {
  669. return $this->renderSuccess();
  670. }
  671. //dd($matches);
  672. //匹配详情页的里面的链接
  673. $pregSon = '/<div\s+class="bbWrapper"><a\s+href="http\S+"/';
  674. $pregSon1 = '/<div\s+class="bbWrapper"><div>\s+<a\s+href="http\S+"/';
  675. $posts = array_slice($matches[0], 2, 3);
  676. //dd($posts);
  677. //$titleStr = 'rel="nofollow ugc noopener">Scoring Endgame | Former CDC Tobacco Control Director Talks Battle Over Vaping | RegWatch</a>';
  678. $pregTitleSon = '/rel="nofollow\s+ugc\s+noopener">.+<\/a>/';
  679. $articles = [];
  680. foreach ($posts as $key => $match) {
  681. $matches1 = [];
  682. $matches2 = [];
  683. $ps = strpos($match, '/', 0);
  684. if ($ps === false) {
  685. continue;
  686. }
  687. //$pe = strrpos($match,'/',0);
  688. $uixHref = substr($match, $ps, -2);
  689. //dd($uixHref);
  690. sleep(1);
  691. $f1 = file_get_contents($ecfHost . $uixHref);
  692. //file_put_contents('b.html',$f1);
  693. //dd('hahaha');
  694. if (empty($f1)) {
  695. continue;
  696. }
  697. //file_put_contents('b.html',$f1);
  698. //dd($uixHref,$f1);
  699. //todo
  700. preg_match($pregSon, $f1, $matches1);
  701. //dd($matches1);
  702. if (empty($matches1)) {
  703. //dd('ooo');
  704. preg_match($pregSon1, $f1, $matches1);
  705. //dd($matches1);
  706. if (empty($matches1)) {
  707. continue;
  708. }
  709. }
  710. //文章详情的原始链接
  711. $postDetailOriginal = $matches1[0];
  712. $ps3 = strpos($postDetailOriginal, 'f', 0);
  713. if ($ps3 === false) {
  714. continue;
  715. }
  716. $postDetailOriginal = substr($postDetailOriginal, $ps3 + 3, -1);
  717. //dd($postDetailOriginal);
  718. //文章的标题
  719. preg_match($pregTitleSon, $f1, $matches2);
  720. dd($matches2);
  721. $postTitle = $matches2[0];
  722. $ps1 = strpos($postTitle, '>', 0);
  723. if ($ps1 === false) {
  724. continue;
  725. }
  726. $title = substr($postTitle, $ps1 + 1, -4);
  727. $article = [
  728. "title" => $title,
  729. "show_type" => 10,
  730. "category_id" => 10002,
  731. "image_id" => 0,
  732. "content" => '<a href="' . $postDetailOriginal . '">' . $title . '</a>',
  733. "sort" => 100,
  734. 'status' => 1,
  735. "virtual_views" => rand(100, 500),
  736. "actual_views" => rand(100, 500),
  737. "is_delete" => 0,
  738. "store_id" => 10001,
  739. "create_time" => time(),
  740. "update_time" => time(),
  741. ];
  742. $articles[] = $article;
  743. //$detail2 = file_get_contents($postDetail);
  744. //dd($matches1[0]);
  745. }
  746. dd($articles);
  747. file_put_contents('a.html', $f);
  748. dd($f);
  749. }
  750. }