Pair.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. <?php
  2. namespace App\Http\Controllers\Crontab;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Pair\CheckService;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Redis;
  7. use App\Http\Controllers\Core\Ding;
  8. use App\Models\Fpdx\PairModel;
  9. use App\Models\Fpdx\ActivityModel;
  10. use Ixudra\Curl\Facades\Curl;
  11. class Pair extends Controller
  12. {
  13. /**
  14. * 获取当前期数
  15. * @return mixed
  16. */
  17. public function getTodayStageId()
  18. {
  19. $stageId = ActivityModel::where(['signend_time' => mktime(12, 0, 0)])->value('stage_id');
  20. return $stageId;
  21. }
  22. /**
  23. * @param $girl
  24. * @param $boy
  25. * @return bool
  26. * 1 => '年龄必须比我大',
  27. * 2 => '年龄必须比我小',
  28. * 3 => '身高必须比我高',
  29. * 4 => '身高必须比我矮',
  30. * 5 => '必须是同校',
  31. * 6 => '必须同城',
  32. * 7 => '必须是不同校',
  33. * 8 => '接受同省调剂',
  34. * 9 => '必须是同乡'
  35. */
  36. public function checkLike($girl, $boy)
  37. {
  38. if ($girl['pair_province'] == 1 || $boy['pair_province'] == 1) {
  39. $girl_s = $girl['address'] ? explode('-', trim($girl['address'])) : null;
  40. $boy_s = $boy['address'] ? explode('-', trim($boy['address'])) : null;
  41. if (empty($girl_s) || empty($boy_s)) {
  42. return false;
  43. } else {
  44. $boy_s_a = $boy_s[0];
  45. $girl_s_a = $girl_s[0];
  46. if (empty($boy_s_a) || empty($girl_s_a)) {
  47. return false;
  48. }
  49. if ($boy_s_a != $girl_s_a) {
  50. return false;
  51. }
  52. }
  53. }
  54. if (in_array($boy['uid'], $girl['pairs'])) {
  55. return false;
  56. }
  57. if ($girl['sex'] != $boy['sxo'] || $boy['sex'] != $girl['sxo']) {
  58. return false;
  59. }
  60. $boy_age = date('Y') - intval($boy['age']);
  61. $girl_age = date('Y') - intval($girl['age']);
  62. //begin
  63. if (
  64. ($girl['pair_min_age'] > 9
  65. || $boy['pair_min_age'] > 9)
  66. && abs($girl_age - $boy_age) > 4
  67. ) {
  68. return false;
  69. }
  70. if (
  71. $boy_age < ($girl_age - $girl['pair_min_age'])
  72. || $boy_age > ($girl_age + $girl['pair_max_age'])
  73. || $girl_age < ($boy_age - $boy['pair_min_age'])
  74. || $girl_age > ($boy_age + $boy['pair_max_age'])
  75. ) {
  76. return false;
  77. }
  78. if ($girl['sex'] != $boy['sex']) {
  79. if ($boy['sex'] == 1) { # 男boy女girl
  80. if ($boy['height'] < ($girl['height'] + 5)) {
  81. return false;
  82. }
  83. } else { # 男girl女boy
  84. if ($girl['height'] < ($boy['height'] + 5)) {
  85. return false;
  86. }
  87. }
  88. }
  89. $girl['likes'] = $girl['fpdx_like'] ? explode(',', trim($girl['fpdx_like'], ',')) : [];
  90. $boy['likes'] = $boy['fpdx_like'] ? explode(',', trim($boy['fpdx_like'], ',')) : [];
  91. foreach ($girl['likes'] as $girl_like) {
  92. $self = $girl;
  93. $other = $boy;
  94. switch ($girl_like) {
  95. case 1: // 年龄必须比我大; 年龄差距最大4岁
  96. $self_age = time() - strtotime($self['age']);
  97. $other_age = time() - strtotime($other['age']);
  98. if ($other_age < $self_age) {
  99. return false;
  100. }
  101. break;
  102. case 2: // 年龄必须比我小; 年龄差距最大4岁
  103. $self_age = time() - strtotime($self['age']);
  104. $other_age = time() - strtotime($other['age']);
  105. if ($other_age > $self_age) {
  106. return false;
  107. }
  108. break;
  109. case 3: // 身高必须比我高
  110. if ($other['height'] <= $self['height']) {
  111. return false;
  112. }
  113. break;
  114. case 4: // 身高必须比我矮
  115. if ($other['height'] >= $self['height']) {
  116. return false;
  117. }
  118. break;
  119. case 5: // 必须是同校
  120. if ($self['school'] != $other['school']) {
  121. return false;
  122. }
  123. break;
  124. case 6: // 必须同城
  125. if ($self['address'] != $other['address']) {
  126. return false;
  127. }
  128. break;
  129. case 7: // 必须是不同校
  130. if ($self['school'] == $other['school']) {
  131. return false;
  132. }
  133. break;
  134. case 9: // 必须是同乡
  135. if ($self['home'] != $other['home']) {
  136. return false;
  137. }
  138. break;
  139. case -3:
  140. case -2:
  141. case -1:
  142. default:
  143. break;
  144. }
  145. }
  146. foreach ($boy['likes'] as $boy_like) {
  147. $self = $boy;
  148. $other = $girl;
  149. switch ($boy_like) {
  150. case 1: // 年龄必须比我大; 年龄差距最大4岁
  151. $self_age = time() - strtotime($self['age']);
  152. $other_age = time() - strtotime($other['age']);
  153. if ($other_age < $self_age) {
  154. return false;
  155. }
  156. break;
  157. case 2: // 年龄必须比我小; 年龄差距最大4岁
  158. $self_age = time() - strtotime($self['age']);
  159. $other_age = time() - strtotime($other['age']);
  160. if ($other_age > $self_age) {
  161. return false;
  162. }
  163. break;
  164. case 3: // 身高必须比我高
  165. if ($other['height'] <= $self['height']) {
  166. return false;
  167. }
  168. break;
  169. case 4: // 身高必须比我矮
  170. if ($other['height'] >= $self['height']) {
  171. return false;
  172. }
  173. break;
  174. case 5: // 必须是同校
  175. if ($self['school'] != $other['school']) {
  176. return false;
  177. }
  178. break;
  179. case 6: // 必须同城
  180. if ($self['address'] != $other['address']) {
  181. return false;
  182. }
  183. break;
  184. case 7: // 必须是不同校
  185. if ($self['school'] == $other['school']) {
  186. return false;
  187. }
  188. break;
  189. case 9: // 必须是同乡
  190. if ($self['home'] != $other['home']) {
  191. return false;
  192. }
  193. break;
  194. case -3:
  195. case -2:
  196. case -1:
  197. default:
  198. break;
  199. }
  200. }
  201. return true;
  202. }
  203. /**
  204. *
  205. * @param $girl
  206. * @param $boy
  207. * @return bool
  208. * 1 => '年龄必须比我大',
  209. * 2 => '年龄必须比我小',
  210. * 3 => '身高必须比我高',
  211. * 4 => '身高必须比我矮',
  212. * 5 => '必须是同校',
  213. * 6 => '必须同城',
  214. * 7 => '必须是不同校',
  215. * 8 => '接受同省调剂',
  216. * 9 => '必须是同乡'
  217. */
  218. public function checkLike2Sheng($girl, $boy)
  219. {
  220. if ($girl['pair_province'] == 0 && $girl['pair_all'] == 0) {
  221. return false;
  222. }
  223. if ($boy['pair_province'] == 0 && $boy['pair_all'] == 0) {
  224. return false;
  225. }
  226. $girl_s = $girl['address'] ? explode('-', trim($girl['address'])) : null;
  227. $boy_s = $boy['address'] ? explode('-', trim($boy['address'])) : null;
  228. if (empty($girl_s) || empty($boy_s)) {
  229. return false;
  230. } else {
  231. $boy_s_a = $boy_s[0];
  232. $girl_s_a = $girl_s[0];
  233. if (empty($boy_s_a) || empty($girl_s_a)) {
  234. return false;
  235. }
  236. if ($boy_s_a != $girl_s_a) {
  237. return false;
  238. }
  239. }
  240. if (in_array($boy['uid'], $girl['pairs'])) {
  241. return false;
  242. }
  243. if ($girl['sex'] != $boy['sxo'] || $boy['sex'] != $girl['sxo']) {
  244. return false;
  245. }
  246. $boy_age = date('Y') - intval($boy['age']);
  247. $girl_age = date('Y') - intval($girl['age']);
  248. //begin
  249. if (
  250. ($girl['pair_min_age'] > 9
  251. || $boy['pair_min_age'] > 9)
  252. && abs($girl_age - $boy_age) > 4
  253. ) {
  254. return false;
  255. }
  256. if (
  257. $boy_age < ($girl_age - $girl['pair_min_age'])
  258. || $boy_age > ($girl_age + $girl['pair_max_age'])
  259. || $girl_age < ($boy_age - $boy['pair_min_age'])
  260. || $girl_age > ($boy_age + $boy['pair_max_age'])
  261. ) {
  262. return false;
  263. }
  264. if ($girl['sex'] != $boy['sex']) {
  265. if ($boy['sex'] == 1) { # 男boy女girl
  266. if ($boy['height'] < ($girl['height'] + 5)) {
  267. return false;
  268. }
  269. } else { # 男girl女boy
  270. if ($girl['height'] < ($boy['height'] + 5)) {
  271. return false;
  272. }
  273. }
  274. }
  275. $girl['likes'] = $girl['fpdx_like'] ? explode(',', trim($girl['fpdx_like'], ',')) : [];
  276. $boy['likes'] = $boy['fpdx_like'] ? explode(',', trim($boy['fpdx_like'], ',')) : [];
  277. foreach ($girl['likes'] as $girl_like) {
  278. $self = $girl;
  279. $other = $boy;
  280. switch ($girl_like) {
  281. case 1: // 年龄必须比我大; 年龄差距最大4岁
  282. $self_age = time() - strtotime($self['age']);
  283. $other_age = time() - strtotime($other['age']);
  284. if ($other_age < $self_age) {
  285. return false;
  286. }
  287. break;
  288. case 2: // 年龄必须比我小; 年龄差距最大4岁
  289. $self_age = time() - strtotime($self['age']);
  290. $other_age = time() - strtotime($other['age']);
  291. if ($other_age > $self_age) {
  292. return false;
  293. }
  294. break;
  295. case 3: // 身高必须比我高
  296. if ($other['height'] <= $self['height']) {
  297. return false;
  298. }
  299. break;
  300. case 4: // 身高必须比我矮
  301. if ($other['height'] >= $self['height']) {
  302. return false;
  303. }
  304. break;
  305. case 7: // 必须是不同校
  306. if ($self['school'] == $other['school']) {
  307. return false;
  308. }
  309. break;
  310. case 8: // 必须同省
  311. $girl_s = $girl['address'] ? explode('-', trim($girl['address'])) : null;
  312. $boy_s = $boy['address'] ? explode('-', trim($boy['address'])) : null;
  313. if (empty($girl_s) || empty($boy_s)) {
  314. return false;
  315. } else {
  316. $boy_s_a = $boy_s[0];
  317. $girl_s_a = $girl_s[0];
  318. if (empty($boy_s_a) || empty($girl_s_a)) {
  319. return false;
  320. }
  321. if ($boy_s_a != $girl_s_a) {
  322. return false;
  323. }
  324. }
  325. break;
  326. case -2:
  327. case -3:
  328. case -1:
  329. default:
  330. break;
  331. }
  332. }
  333. foreach ($boy['likes'] as $boy_like) {
  334. $self = $boy;
  335. $other = $girl;
  336. switch ($boy_like) {
  337. case 1: // 年龄必须比我大; 年龄差距最大4岁
  338. $self_age = time() - strtotime($self['age']);
  339. $other_age = time() - strtotime($other['age']);
  340. if ($other_age < $self_age) {
  341. return false;
  342. }
  343. break;
  344. case 2: // 年龄必须比我小; 年龄差距最大4岁
  345. $self_age = time() - strtotime($self['age']);
  346. $other_age = time() - strtotime($other['age']);
  347. if ($other_age > $self_age) {
  348. return false;
  349. }
  350. break;
  351. case 3: // 身高必须比我高
  352. if ($other['height'] <= $self['height']) {
  353. return false;
  354. }
  355. break;
  356. case 4: // 身高必须比我矮
  357. if ($other['height'] >= $self['height']) {
  358. return false;
  359. }
  360. break;
  361. case 7: // 必须是不同校
  362. if ($self['school'] == $other['school']) {
  363. return false;
  364. }
  365. break;
  366. case 8: // 必须同省
  367. $girl_s = $girl['address'] ? explode('-', trim($girl['address'])) : null;
  368. $boy_s = $boy['address'] ? explode('-', trim($boy['address'])) : null;
  369. if (empty($girl_s) || empty($boy_s)) {
  370. return false;
  371. } else {
  372. $boy_s_a = $boy_s[0];
  373. $girl_s_a = $girl_s[0];
  374. if (empty($boy_s_a) || empty($girl_s_a)) {
  375. return false;
  376. }
  377. if ($boy_s_a != $girl_s_a) {
  378. return false;
  379. }
  380. }
  381. break;
  382. case -3:
  383. case -2:
  384. case -1:
  385. default:
  386. break;
  387. }
  388. }
  389. return true;
  390. }
  391. /**
  392. * @param $girl
  393. * @param $boy
  394. * @return bool
  395. * 1 => '年龄必须比我大',
  396. * 2 => '年龄必须比我小',
  397. * 3 => '身高必须比我高',
  398. * 4 => '身高必须比我矮',
  399. * 5 => '必须是同校',
  400. * 6 => '必须同城',
  401. * 7 => '必须是不同校',
  402. * 8 => '接受同省调剂',
  403. * 9 => '必须是同乡'
  404. */
  405. public function checkLike2All($girl, $boy)
  406. {
  407. if ($girl['pair_all'] == 0) {
  408. return false;
  409. }
  410. if ($boy['pair_all'] == 0) {
  411. return false;
  412. }
  413. // 是否匹配过
  414. if (in_array($boy['uid'], $girl['pairs'])) {
  415. return false;
  416. }
  417. // 性别-性取向
  418. if ($girl['sex'] != $boy['sxo'] || $boy['sex'] != $girl['sxo']) {
  419. return false;
  420. }
  421. // 年龄
  422. $boy_age = date('Y') - intval($boy['age']);
  423. $girl_age = date('Y') - intval($girl['age']);
  424. //begin
  425. if (
  426. ($girl['pair_min_age'] > 9
  427. || $boy['pair_min_age'] > 9)
  428. && abs($girl_age - $boy_age) > 4
  429. ) {
  430. return false;
  431. }
  432. if (
  433. $boy_age < ($girl_age - $girl['pair_min_age'])
  434. || $boy_age > ($girl_age + $girl['pair_max_age'])
  435. || $girl_age < ($boy_age - $boy['pair_min_age'])
  436. || $girl_age > ($boy_age + $boy['pair_max_age'])
  437. ) {
  438. return false;
  439. }
  440. // 身高
  441. if ($girl['sex'] != $boy['sex']) {
  442. if ($boy['sex'] == 1) { # 男boy女girl
  443. if ($boy['height'] < ($girl['height'] + 5)) {
  444. return false;
  445. }
  446. } else { # 男girl女boy
  447. if ($girl['height'] < ($boy['height'] + 5)) {
  448. return false;
  449. }
  450. }
  451. }
  452. // 勾选匹配条件
  453. $girl['likes'] = $girl['fpdx_like'] ? explode(',', trim($girl['fpdx_like'], ',')) : [];
  454. $boy['likes'] = $boy['fpdx_like'] ? explode(',', trim($boy['fpdx_like'], ',')) : [];
  455. foreach ($girl['likes'] as $girl_like) {
  456. $self = $girl;
  457. $other = $boy;
  458. switch ($girl_like) {
  459. case 1: // 年龄必须比我大; 年龄差距最大4岁
  460. $self_age = time() - strtotime($self['age']);
  461. $other_age = time() - strtotime($other['age']);
  462. if ($other_age < $self_age) {
  463. return false;
  464. }
  465. break;
  466. case 2: // 年龄必须比我小; 年龄差距最大4岁
  467. $self_age = time() - strtotime($self['age']);
  468. $other_age = time() - strtotime($other['age']);
  469. if ($other_age > $self_age) {
  470. return false;
  471. }
  472. break;
  473. case 3: // 身高必须比我高
  474. if ($other['height'] <= $self['height']) {
  475. return false;
  476. }
  477. break;
  478. case 4: // 身高必须比我矮
  479. if ($other['height'] >= $self['height']) {
  480. return false;
  481. }
  482. break;
  483. case 7: // 必须是不同校
  484. if ($self['school'] == $other['school']) {
  485. return false;
  486. }
  487. break;
  488. case -3:
  489. case -2:
  490. case -1:
  491. default:
  492. break;
  493. }
  494. }
  495. foreach ($boy['likes'] as $boy_like) {
  496. $self = $boy;
  497. $other = $girl;
  498. switch ($boy_like) {
  499. case 1: // 年龄必须比我大
  500. $self_age = time() - strtotime($self['age']);
  501. $other_age = time() - strtotime($other['age']);
  502. if ($other_age < $self_age) {
  503. return false;
  504. }
  505. break;
  506. case 2: // 年龄必须比我小
  507. $self_age = time() - strtotime($self['age']);
  508. $other_age = time() - strtotime($other['age']);
  509. if ($other_age > $self_age) {
  510. return false;
  511. }
  512. break;
  513. case 3: // 身高必须比我高
  514. if ($other['height'] <= $self['height']) {
  515. return false;
  516. }
  517. break;
  518. case 4: // 身高必须比我矮
  519. if ($other['height'] >= $self['height']) {
  520. return false;
  521. }
  522. break;
  523. case 7: // 必须是不同校
  524. if ($self['school'] == $other['school']) {
  525. return false;
  526. }
  527. break;
  528. case -3:
  529. case -2:
  530. case -1:
  531. default:
  532. break;
  533. }
  534. }
  535. return true;
  536. }
  537. /**
  538. * 匹配某期用户
  539. * @param callable $callback
  540. * @param array $argv
  541. * @return bool
  542. * @throws \Exception
  543. */
  544. public function pipei(callable $callback, array $argv)
  545. {
  546. $callback_checkLike = array(new self(), "checkLike");
  547. $callback_checkLike2Shenge = array(new self(), "checkLike2Sheng");
  548. $callback_checkLike2All = array(new self(), "checkLike2All");
  549. // 特权匹配 92
  550. dump("开始92特权匹配");
  551. $base_score = 92;
  552. // 完全符合条件
  553. dump("完全符合条件");
  554. $users = call_user_func_array($callback, $argv);
  555. $data = $tmp = $users->toArray();
  556. $this->init($data, $tmp, $callback_checkLike, $base_score);
  557. // 允许同省调剂
  558. dump("同省调剂");
  559. $users = call_user_func_array($callback, $argv);
  560. $data = $tmp = $users->toArray();
  561. $this->init($data, $tmp, $callback_checkLike2Shenge, $base_score);
  562. // 允许全国调剂
  563. dump("全国调剂");
  564. $users = call_user_func_array($callback, $argv);
  565. $data = $tmp = $users->toArray();
  566. $this->init($data, $tmp, $callback_checkLike2All, $base_score);
  567. // 特权匹配 91
  568. dump("开始91特权匹配");
  569. $base_score = 91;
  570. // 完全符合条件
  571. dump("完全符合条件");
  572. $users = call_user_func_array($callback, $argv);
  573. $data = $tmp = $users->toArray();
  574. $this->init($data, $tmp, $callback_checkLike, $base_score);
  575. // 允许同省调剂
  576. dump("同省调剂");
  577. $users = call_user_func_array($callback, $argv);
  578. $data = $tmp = $users->toArray();
  579. $this->init($data, $tmp, $callback_checkLike2Shenge, $base_score);
  580. // 允许全国调剂
  581. dump("全国调剂");
  582. $users = call_user_func_array($callback, $argv);
  583. $data = $tmp = $users->toArray();
  584. $this->init($data, $tmp, $callback_checkLike2All, $base_score);
  585. // 特权匹配 90
  586. dump("开始90特权匹配");
  587. $base_score = 91;
  588. // 完全符合条件
  589. dump("完全符合条件");
  590. $users = call_user_func_array($callback, $argv);
  591. $data = $tmp = $users->toArray();
  592. $this->init($data, $tmp, $callback_checkLike, $base_score);
  593. // 允许同省调剂
  594. dump("同省调剂");
  595. $users = call_user_func_array($callback, $argv);
  596. $data = $tmp = $users->toArray();
  597. $this->init($data, $tmp, $callback_checkLike2Shenge, $base_score);
  598. // 允许全国调剂
  599. dump("全国调剂");
  600. $users = call_user_func_array($callback, $argv);
  601. $data = $tmp = $users->toArray();
  602. $this->init($data, $tmp, $callback_checkLike2All, $base_score);
  603. // 普通匹配
  604. dump("开始普通匹配");
  605. $base_score = 0;
  606. // 完全符合条件
  607. dump("完全符合条件");
  608. $users = call_user_func_array($callback, $argv);
  609. $data = $tmp = $users->toArray();
  610. $this->init($data, $tmp, $callback_checkLike, $base_score);
  611. // 允许同省调剂
  612. dump("同省调剂");
  613. $users = call_user_func_array($callback, $argv);
  614. $data = $tmp = $users->toArray();
  615. $this->init($data, $tmp, $callback_checkLike2Shenge, $base_score);
  616. // 允许全国调剂
  617. dump("全国调剂");
  618. $users = call_user_func_array($callback, $argv);
  619. $data = $tmp = $users->toArray();
  620. $this->init($data, $tmp, $callback_checkLike2All, $base_score);
  621. return true;
  622. }
  623. /**
  624. * 匹配包装器
  625. * @param array $data 待匹配数组1
  626. * @param array $tmp 待匹配数组2
  627. * @param callable $callback
  628. * @param int $base_score 基础匹配分
  629. * @return int 匹配成功的数量
  630. * @throws \Exception
  631. */
  632. public function init($data, $tmp, callable $callback, int $base_score = 0)
  633. {
  634. $count = 0;
  635. foreach ($data as $i => $value) {
  636. foreach ($tmp as $key => $item) {
  637. // 基础匹配分
  638. if ($value['score'] < $base_score && $item['score'] < $base_score) {
  639. continue;
  640. }
  641. // 不可以匹配自己
  642. if ($value['uid'] == $item['uid']) {
  643. continue;
  644. }
  645. // 是否满足条件
  646. if (call_user_func_array($callback, [$value, $item])) {
  647. try {
  648. DB::beginTransaction();
  649. DB::table("kdgx_partner_charge_pair")
  650. ->where('id', $value['pair_id'])->update([
  651. 'partner' => 1,
  652. 'assoc_id' => $item['pair_id']
  653. ]);
  654. DB::table("kdgx_partner_charge_pair")
  655. ->where('id', $item['pair_id'])->update([
  656. 'partner' => 2,
  657. 'assoc_id' => $value['pair_id']
  658. ]);
  659. DB::commit();
  660. $week4_12 = mktime(12, 0, 0, date('m'), date('d') - date('w') + 4, date('Y'));
  661. $week5_12 = mktime(12, 0, 0, date('m'), date('d') - date('w') + 5, date('Y'));
  662. if (time() > $week4_12 && time() < $week5_12) {
  663. Redis::sadd("fpdx_pairs_{$value['uid']}", $item['uid']);
  664. Redis::sadd("fpdx_pairs_{$item['uid']}", $value['uid']);
  665. }
  666. $count++;
  667. unset($tmp[$key]);
  668. break;
  669. } catch (\Exception $e) {
  670. DB::rollBack();
  671. dump($e);
  672. continue;
  673. }
  674. } else {
  675. continue;
  676. }
  677. }
  678. }
  679. return $count;
  680. }
  681. /**
  682. * 匹配
  683. * @param int $stage_id
  684. * @throws \Exception
  685. */
  686. public function index(int $stage_id = 0)
  687. {
  688. if (!$stage_id) {
  689. $stage_id = $this->getTodayStageId();
  690. }
  691. if ($stage_id) {
  692. if (app()->environment() == 'production') {
  693. Curl::to("http://api.deep.fenpeiduixiang.com/api/ding/paircp/begin/{$stage_id}")->get();
  694. }
  695. PairModel::where('stage_id', $stage_id)
  696. ->whereIn('media_id', ['gh_b598cb7474d8', 'gh_c94c95866ca5'])
  697. ->whereBetween('state', [0, 99])->increment('state', 100);
  698. $obj = new PairModel();
  699. // $this->pipei(array($obj, "getPairQuery"), [$stage_id, '72h', '浙江-杭州']);
  700. // $this->pipei(array($obj, "getPairQuery"), [$stage_id, 'qbj']);
  701. $this->pipei(array($obj, "getPairQuery"), [$stage_id, '72h']);
  702. if (app()->environment() == 'production') {
  703. \Curl::to("http://api.deep.fenpeiduixiang.com/api/ding/paircp/end/{$stage_id}")->get();
  704. }
  705. $check = new CheckService();
  706. $check->baocun($stage_id);
  707. $check->check($stage_id);
  708. }
  709. }
  710. /**
  711. * 预匹配
  712. * @param int $stageId
  713. * @throws \Exception
  714. */
  715. public function prePipei($stageId = 0)
  716. {
  717. if (0 == $stageId) {
  718. $activitys = ActivityModel::getActivitys();
  719. $stageId = $activitys['next'];
  720. }
  721. if ($stageId) {
  722. if (app()->environment() == 'production') {
  723. Curl::to("http://api.deep.fenpeiduixiang.com/api/ding/paircp/begin/{$stageId}")->get();
  724. }
  725. $obj = new PairModel();
  726. // $this->pipei(array($obj, "getPairQuery"), array($stageId, '72h', '浙江-杭州'));
  727. $this->pipei(array($obj, "getPairQuery"), array($stageId, '72h'));
  728. // $this->pipei(array($obj, "getPairQuery"), array($stageId, 'qbj'));
  729. if (app()->environment() == 'production') {
  730. Curl::to("http://api.deep.fenpeiduixiang.com/api/ding/paircp/end/{$stageId}")->get();
  731. }
  732. $check = new CheckService();
  733. $check->baocun($stageId);
  734. $check->check($stageId);
  735. }
  736. }
  737. /**
  738. * 预匹配数据恢复
  739. */
  740. public function preRestore()
  741. {
  742. $activitys = ActivityModel::getActivitys();
  743. $stage_id = $activitys['next'];
  744. $last = PairModel::orderBy('stage_id', 'desc')->first();
  745. if (collect($last)->isEmpty() || $last->stage_id != $stage_id) {
  746. Ding::robot([
  747. 'title' => '[分配对象]预匹配|数据恢复',
  748. 'text' => "数据恢复异常"
  749. ]);
  750. return;
  751. }
  752. PairModel::where([['stage_id', $stage_id], ['pair_type', 0]])->update(['assoc_id' => null, 'partner' => 0]);
  753. if (app()->environment() == 'production') {
  754. Ding::robot([
  755. 'title' => '[分配对象]预匹配提醒|数据恢复',
  756. 'text' => "数据恢复正常"
  757. ]);
  758. }
  759. }
  760. }