User.php 26 KB

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