InvitationService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. namespace App\Services\Deed;
  3. use App\Exceptions\AlertException;
  4. use App\Models\Deed\FriendsModel;
  5. use App\Models\Deed\InvitationCardModel;
  6. use App\Models\PartnerModel;
  7. use App\Models\PraiseModel;
  8. use App\Models\User\LikeInviteQuestionModel;
  9. use App\Models\User\SuperLikeModel;
  10. use App\Models\User\UserModel;
  11. use App\Services\Service;
  12. use Illuminate\Database\Eloquent\Builder;
  13. use Illuminate\Support\Facades\DB;
  14. class InvitationService extends Service
  15. {
  16. public const GOOD = array(
  17. 'flower' => 1,
  18. );
  19. public function pay(int $uid, int $invite_uid, int $type)
  20. {
  21. if (false && 6 <= InvitationCardModel::where([['uid', $uid], ['invite_uid', $invite_uid]])->count()) {
  22. throw new AlertException("已达邀请上限", 102);
  23. }
  24. $user = UserModel::findOrFail($uid);
  25. if (1 > $user->red_flower) {
  26. throw new AlertException("小花不够", 101);
  27. }
  28. $user->decrement("red_flower", 1);
  29. DB::table('kdgx_partner_charge_pay_logs')->insert([
  30. 'uid' => $uid,
  31. 'create_at' => time(),
  32. 'type' => 14,
  33. 'red_flower' => 0 - 1,
  34. 'gold_flower' => 0,
  35. 'remark' => "心动邀请",
  36. ]);
  37. return true;
  38. }
  39. /**
  40. * 创建一个邀请
  41. * @param int $uid
  42. * @param int $invite_uid
  43. * @param int $question_type
  44. * @param array $question
  45. * @param $say_hello
  46. * @param array $request
  47. * @param $kk
  48. * @return mixed
  49. * @throws AlertException
  50. */
  51. public function create(
  52. int $uid,
  53. int $invite_uid,
  54. int $question_type,
  55. array $question,
  56. $say_hello,
  57. $paint_id,
  58. $request_content,
  59. $kk
  60. ) {
  61. if ($uid == $invite_uid) {
  62. throw new AlertException("不能邀请自己参加活动哦", 422);
  63. }
  64. $user = UserModel::findOrFail($uid);
  65. $incardmodel = new InvitationCardModel();
  66. $expired_at = time() + 86400 * 2;
  67. $fill = array(
  68. 'uid' => $uid,
  69. 'invite_uid' => $invite_uid,
  70. 'kk' => $kk,
  71. 'type' => 0,
  72. 'expired_at' => $expired_at,
  73. 'say_hello' => $say_hello,
  74. 'paint_id' => $paint_id,
  75. 'request_content' => $request_content,
  76. );
  77. if (0 != $question_type) {
  78. $fill['question_id'] = $question['question_id'];
  79. $fill['question_answer'] = $question['question_answer'];
  80. $fill['question_type'] = $question_type;
  81. }
  82. $invite = $incardmodel->fill($fill);
  83. $invite->save();
  84. try {
  85. $ns = new \App\Services\Deed\NoticeService();
  86. $ns->invitation($uid, $invite_uid, $invite->id, $question_type, true);
  87. } catch (\Exception $exception) {
  88. }
  89. return $invite->id;
  90. }
  91. /**
  92. * 通过id获取邀请信息
  93. * @param int $uid
  94. * @param int $invitation_id
  95. * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
  96. */
  97. public function getById(int $uid, int $invitation_id)
  98. {
  99. $icm = new InvitationCardModel();
  100. $data = InvitationCardModel::findOrFail($invitation_id);
  101. $data->task_question_answer = json_decode($data->task_question_answer, true);
  102. $question = LikeInviteQuestionModel::withTrashed()->find($data->question_id);
  103. if ($question) {
  104. $question->question = $question ? json_decode($question->question, true) : null;
  105. }
  106. $data->question = $question;
  107. if ($data->uid == $uid) {
  108. $iuid = $data->invite_uid;
  109. } else {
  110. $iuid = $data->uid;
  111. }
  112. $partner = PartnerModel::where('uid', $iuid)->first();
  113. if (collect($partner)->isEmpty()) {
  114. $partner = null;
  115. } else {
  116. $user = UserModel::findOrFail($partner->uid, [
  117. 'uid',
  118. 'headimgurl',
  119. 'nickname',
  120. 'age',
  121. 'star',
  122. 'introduce',
  123. 'expect',
  124. 'height',
  125. 'sex',
  126. 'school',
  127. 'address',
  128. 'home',
  129. 'tag_1',
  130. 'tag_2',
  131. 'tag_3',
  132. 'tag_4',
  133. 'weixin',
  134. 'qq',
  135. 'supvip_endat',
  136. ]);
  137. $user->invite_cnt = $icm->where('invite_uid', $iuid)->count();
  138. $partner->setAttribute("user", $user);
  139. // 与self的关系处理
  140. $self = array(
  141. 'friend' => false,
  142. 'praise' => false,
  143. 'invite' => false,
  144. 'superlike' => false,
  145. );
  146. $friend = FriendsModel::where([['uid', $uid], ['friend_uid', $partner->uid]])->first();
  147. $self['friend'] = $friend;
  148. if (PraiseModel::where([['uid', $uid], ['partner_id', $partner->id], ['type', 1]])->exists()) {
  149. $self['praise'] = true;
  150. }
  151. $invite = InvitationCardModel::where([
  152. ['uid', $uid],
  153. ['invite_uid', $partner->uid],
  154. ['expired_at', '>', time()],
  155. ])->groupBy('question_type')->get(['question_type'])->pluck('question_type');
  156. $self['invite'] = $invite;
  157. if (SuperLikeModel::where([['uid', $uid], ['partner_id', $partner->id]])->exists()) {
  158. $self['superlike'] = true;
  159. }
  160. $partner->setAttribute("self", $self);
  161. }
  162. $data->partner = $partner;
  163. return $data;
  164. }
  165. /**
  166. * 接收到的待处理邀请
  167. * @param int $uid
  168. * @param array $pages
  169. * @return array
  170. */
  171. public function receivesByUnhandle(int $uid, array $pages)
  172. {
  173. $icm = new InvitationCardModel();
  174. $total = $icm->where(array(
  175. ['invite_uid', $uid],
  176. ['state', 0],
  177. ['read', 0],
  178. ['expired_at', '>', time()],
  179. ))->count();
  180. $datas = $icm->where(array(['invite_uid', $uid], ['state', 0], ['read', 0], ['expired_at', '>', time()]))
  181. ->skip(($pages['page'] - 1) * $pages['limit'])->take($pages['limit'])->orderBy('id', 'desc')->get();
  182. $users = UserModel::whereIn('uid', $datas->pluck('uid')->toArray())->get([
  183. 'uid',
  184. 'headimgurl',
  185. 'nickname',
  186. 'partner_id',
  187. 'age',
  188. 'star',
  189. 'introduce',
  190. 'expect',
  191. 'height',
  192. 'sex',
  193. 'school',
  194. 'address',
  195. 'home',
  196. 'tag_1',
  197. 'tag_2',
  198. 'tag_3',
  199. 'tag_4',
  200. 'wx_auth',
  201. 'identity_auth',
  202. 'supvip_endat',
  203. ])->toArray();
  204. $users = array_combine(array_column($users, 'uid'), $users);
  205. $partners = PartnerModel::whereIn('id', array_column($users, 'partner_id'))->get()->toArray();
  206. $partners = array_combine(array_column($partners, 'id'), $partners);
  207. $result = array();
  208. $index_uid = array();
  209. $i = 0;
  210. foreach ($datas as $data) {
  211. try {
  212. $data = $invite = $data->toArray();
  213. $duid = $data['uid'];
  214. if (!isset($index_uid[$duid])) {
  215. $index_uid[$duid] = $i;
  216. $data['invites'][] = $invite;
  217. $user = $users[$duid];
  218. $user['invite_cnt'] = $icm->where('invite_uid', $duid)->count();
  219. $partner = $partners[$user['partner_id']];
  220. $partner['user'] = $user;
  221. $data['partner'] = $partner;
  222. $result[$i] = $data;
  223. $i++;
  224. } else {
  225. $result[$index_uid[$duid]]['invites'][] = $invite;
  226. }
  227. } catch (\Exception $e) {
  228. continue;
  229. }
  230. }
  231. return [
  232. 'total' => $total,
  233. 'page' => $pages['page'],
  234. 'limit' => $pages['limit'],
  235. 'list' => $result,
  236. ];
  237. }
  238. /**
  239. * 待处理邀请
  240. * @param int $uid
  241. * @param array $pages
  242. * @return array
  243. * @throws \Exception
  244. */
  245. public function unhandle(int $uid, array $pages)
  246. {
  247. $icm = new InvitationCardModel();
  248. $inviteme_cnt = $icm->where(array(['invite_uid', $uid], ['state', 0], ['expired_at', '>', time()]))->count();
  249. $inviteother_cnt = $icm->where(array(
  250. ['uid', $uid],
  251. ['state', '!=', 1],
  252. ['expired_at', '>', time()],
  253. ))->orWhere(array(['uid', $uid], ['send_read', 0]))->count();
  254. if ($pages['limit'] * $pages['page'] <= $inviteme_cnt) {
  255. $datas = $icm->where(array(
  256. ['invite_uid', $uid],
  257. ['state', 0],
  258. ['expired_at', '>', time()],
  259. ))->skip(($pages['page'] - 1) * $pages['limit'])->take($pages['limit'])->orderBy('id', 'desc')->get();
  260. } else {
  261. if ($pages['limit'] * ($pages['page'] - 1) < $inviteme_cnt) {
  262. $datas = $icm->where(array(
  263. ['invite_uid', $uid],
  264. ['state', 0],
  265. ['expired_at', '>', time()],
  266. ))->skip(($pages['page'] - 1) * $pages['limit'])->take($inviteme_cnt - $pages['limit'] * ($pages['page'] - 1))->orderBy(
  267. 'id',
  268. 'desc'
  269. )->get();
  270. $datas2 = $icm->where(array(
  271. ['uid', $uid],
  272. ['state', '!=', 1],
  273. ['expired_at', '>', time()],
  274. ))->orWhere(array(
  275. ['uid', $uid],
  276. ['send_read', 0],
  277. ))->skip(0)->take($pages['limit'] * $pages['page'] - $inviteme_cnt)->orderBy('id', 'desc')->get();
  278. foreach ($datas2 as $value2) {
  279. $datas->push($value2);
  280. }
  281. } else {
  282. $datas = $icm->where(array(
  283. ['uid', $uid],
  284. ['state', '!=', 1],
  285. ['expired_at', '>', time()],
  286. ))->orWhere(array(
  287. ['uid', $uid],
  288. ['send_read', 0],
  289. ))->skip(($pages['page'] - 1) * $pages['limit'] - $inviteme_cnt)->take($pages['limit'])->orderBy(
  290. 'id',
  291. 'desc'
  292. )->get();
  293. }
  294. }
  295. $uids = array_unique(array_merge($datas->pluck('invite_uid')->toArray(), $datas->pluck('uid')->toArray()));
  296. $users = UserModel::whereIn('uid', $uids)->get([
  297. 'uid',
  298. 'headimgurl',
  299. 'nickname',
  300. 'partner_id',
  301. 'age',
  302. 'star',
  303. 'introduce',
  304. 'expect',
  305. 'height',
  306. 'sex',
  307. 'school',
  308. 'address',
  309. 'home',
  310. 'tag_1',
  311. 'tag_2',
  312. 'tag_3',
  313. 'tag_4',
  314. 'wx_auth',
  315. 'identity_auth',
  316. 'supvip_endat',
  317. ])->toArray();
  318. $users = array_combine(array_column($users, 'uid'), $users);
  319. $partners = PartnerModel::whereIn('id', array_column($users, 'partner_id'))->get()->toArray();
  320. $partners = array_combine(array_column($partners, 'id'), $partners);
  321. $partners[0] = null;
  322. $result = array();
  323. $index_uid = array();
  324. $index_inviteuid = array();
  325. $i = $j = 0;
  326. foreach ($datas as $data) {
  327. try {
  328. $data = $invite = $data->toArray();
  329. $duid = $data['uid'];
  330. if ($duid == $uid) {
  331. $duid = $data['invite_uid'];
  332. if (!isset($index_uid[$duid])) {
  333. $index_uid[$duid] = $i;
  334. $data['invites'][] = $invite;
  335. $user = $users[$duid];
  336. $user['invite_cnt'] = $icm->where('invite_uid', $duid)->count();
  337. $partner = $partners[$user['partner_id']];
  338. $partner['user'] = $user;
  339. $data['partner'] = $partner;
  340. $result[$i] = $data;
  341. $i++;
  342. } else {
  343. $result[$index_uid[$duid]]['invites'][] = $invite;
  344. }
  345. } else {
  346. if (!isset($index_inviteuid[$duid])) {
  347. $index_inviteuid[$duid] = $i;
  348. $data['ids'] = [$data['id']];
  349. $user = $users[$duid];
  350. $user['invite_cnt'] = $icm->where('invite_uid', $duid)->count();
  351. $partner = $partners[$user['partner_id']];
  352. $partner['user'] = $user;
  353. $data['partner'] = $partner;
  354. $result[$i] = $data;
  355. $i++;
  356. } else {
  357. array_push($result[$index_inviteuid[$duid]]['ids'], $data['id']);
  358. }
  359. }
  360. } catch (\Exception $exception) {
  361. throw $exception;
  362. }
  363. }
  364. return [
  365. 'total' => $inviteme_cnt + $inviteother_cnt,
  366. 'page' => $pages['page'],
  367. 'limit' => $pages['limit'],
  368. 'list' => $result,
  369. ];
  370. }
  371. /**
  372. * 接收到的邀请
  373. * @param int $uid
  374. * @param array $pages
  375. * @param bool $onlyreceive
  376. * @return array
  377. */
  378. public function receives(int $uid, array $pages, bool $onlyreceive = false)
  379. {
  380. $icm = new InvitationCardModel();
  381. // 未读邀请
  382. $count = $icm->where([['read', 0], ['invite_uid', $uid]])->count();
  383. if ($onlyreceive) {
  384. $datas = $icm->where(array(['invite_uid', $uid], ['state', 1]))
  385. ->skip(($pages['page'] - 1) * $pages['limit'])->take($pages['limit'])
  386. ->orderBy('id', 'desc')->get();
  387. $total = $icm->where(array(['invite_uid', $uid], ['state', 1]))->count();
  388. } else {
  389. $total = $icm->where('invite_uid', $uid)->count();
  390. $datas = $icm->where('invite_uid', $uid)
  391. ->skip(($pages['page'] - 1) * $pages['limit'])->take($pages['limit'])
  392. ->orderBy('id', 'desc')->get();
  393. }
  394. $result = array();
  395. foreach ($datas as &$data) {
  396. try {
  397. $partner = PartnerModel::where('uid', $data->uid)->first();
  398. if (collect($partner)->isEmpty()) {
  399. $partner = null;
  400. } else {
  401. $user = UserModel::findOrFail($partner->uid, [
  402. 'uid',
  403. 'headimgurl',
  404. 'nickname',
  405. 'age',
  406. 'star',
  407. 'introduce',
  408. 'expect',
  409. 'height',
  410. 'sex',
  411. 'school',
  412. 'address',
  413. 'home',
  414. 'tag_1',
  415. 'tag_2',
  416. 'tag_3',
  417. 'tag_4',
  418. 'wx_auth',
  419. 'identity_auth',
  420. 'be_vip_at',
  421. 'supvip_endat',
  422. ]);
  423. $user->invite_cnt = $icm->where('invite_uid', $data->uid)->count();
  424. $partner->setAttribute("user", $user);
  425. }
  426. $data->partner = $partner;
  427. if ($data->state == 0) {
  428. $data->sort = 2;
  429. $result[] = $data;
  430. continue;
  431. }
  432. if ($data->state != 0 && $data->expired_at < time()) {
  433. $data->sort = 3;
  434. $result[] = $data;
  435. continue;
  436. }
  437. } catch (\Exception $e) {
  438. continue;
  439. }
  440. $data->sort = 4;
  441. $result[] = $data;
  442. }
  443. // 清空阅读邀请通知的记录
  444. try {
  445. $ns = new NoticeService();
  446. $ns->readNotice($uid);
  447. } catch (\Exception $e) {
  448. }
  449. return [
  450. 'total' => $total,
  451. 'page' => $pages['page'],
  452. 'limit' => $pages['limit'],
  453. 'tag_count' => $count,
  454. 'list' => $result,
  455. ];
  456. }
  457. /**
  458. * 发出的邀请
  459. * @param int $uid
  460. * @param array $pages
  461. * @param bool $onlyreceive
  462. * @return array
  463. */
  464. public function sends(int $uid, array $pages, bool $onlyreceive = false)
  465. {
  466. $icm = new InvitationCardModel();
  467. // 未读通知的数量
  468. $count = $icm->where(array(['uid', $uid], ['send_read', 0], ['question_type', "!=", 0]))->count();
  469. $total = $icm->where('uid', $uid)->where('question_type', "!=", 0)->count();
  470. $datas = $icm->where('uid', $uid)->where('question_type', "!=", 0)
  471. ->when($onlyreceive, function ($query) {
  472. /** @var Builder $query */
  473. return $query->where('state', 1);
  474. })->orderBy('id', 'desc')->skip(($pages['page'] - 1) * $pages['limit'])
  475. ->take($pages['limit'])->get();
  476. foreach ($datas as &$data) {
  477. try {
  478. $partner = PartnerModel::where('uid', $data->invite_uid)->first();
  479. if (collect($partner)->isEmpty()) {
  480. $partner = null;
  481. } else {
  482. $user = UserModel::findOrFail($partner->uid, [
  483. 'uid',
  484. 'headimgurl',
  485. 'nickname',
  486. 'age',
  487. 'star',
  488. 'introduce',
  489. 'expect',
  490. 'height',
  491. 'sex',
  492. 'school',
  493. 'address',
  494. 'home',
  495. 'tag_1',
  496. 'tag_2',
  497. 'tag_3',
  498. 'tag_4',
  499. 'wx_auth',
  500. 'identity_auth',
  501. 'be_vip_at',
  502. 'supvip_endat',
  503. ]);
  504. $user->invite_cnt = $icm->where('invite_uid', $data->invite_uid)->count();
  505. $partner->setAttribute("user", $user);
  506. }
  507. $data->partner = $partner;
  508. } catch (\Exception $e) {
  509. continue;
  510. }
  511. }
  512. return [
  513. 'total' => $total,
  514. 'page' => $pages['page'],
  515. 'limit' => $pages['limit'],
  516. 'tag_count' => $count,
  517. 'list' => $datas,
  518. ];
  519. }
  520. /**
  521. * 所有邀请
  522. * @param int $uid
  523. * @param array $pages
  524. * @return array
  525. */
  526. public function list(int $uid, array $pages)
  527. {
  528. $icm = new InvitationCardModel();
  529. // 未读通知的数量
  530. $count = $icm->where(array(
  531. ['uid', $uid],
  532. ['send_read', 0],
  533. ['question_type', "!=", 0],
  534. ))->count() + $icm->where([['read', 0], ['invite_uid', $uid], ['question_type', "!=", 0]])->count();
  535. $total = $icm->where(array(['uid', $uid], ['question_type', "!=", 0]))->orWhere(array(
  536. ['invite_uid', $uid],
  537. ['question_type', "!=", 0],
  538. ))->count();
  539. $datas = $icm->where(array(['uid', $uid], ['question_type', "!=", 0]))->orWhere(array(
  540. ['invite_uid', $uid],
  541. ['question_type', "!=", 0],
  542. ))
  543. ->skip(($pages['page'] - 1) * $pages['limit'])->take($pages['limit'])
  544. ->orderBy('id', 'desc')->get();
  545. foreach ($datas as &$data) {
  546. try {
  547. $suid = $uid == $data->uid ? $data->invite_uid : $data->uid;
  548. $partner = PartnerModel::where('uid', $suid)->first();
  549. if (collect($partner)->isEmpty()) {
  550. $partner = null;
  551. } else {
  552. $user = UserModel::findOrFail($partner->uid, [
  553. 'uid',
  554. 'headimgurl',
  555. 'nickname',
  556. 'age',
  557. 'star',
  558. 'introduce',
  559. 'expect',
  560. 'height',
  561. 'sex',
  562. 'school',
  563. 'address',
  564. 'home',
  565. 'tag_1',
  566. 'tag_2',
  567. 'tag_3',
  568. 'tag_4',
  569. 'wx_auth',
  570. 'identity_auth',
  571. 'be_vip_at',
  572. 'supvip_endat',
  573. ]);
  574. $user->invite_cnt = $icm->where('invite_uid', $suid)->count();
  575. $partner->setAttribute("user", $user);
  576. }
  577. $data->partner = $partner;
  578. } catch (\Exception $e) {
  579. continue;
  580. }
  581. }
  582. return [
  583. 'total' => $total,
  584. 'page' => $pages['page'],
  585. 'limit' => $pages['limit'],
  586. 'tag_count' => $count,
  587. 'list' => $datas,
  588. ];
  589. }
  590. /**
  591. * 同意/忽略 邀请
  592. * @param int $invite_id
  593. * @param int $uid
  594. * @param int $state
  595. * @return bool
  596. * @throws AlertException
  597. */
  598. public function fixstate(int $invite_id, int $uid, int $state)
  599. {
  600. $invite = InvitationCardModel::findOrFail($invite_id);
  601. if ($invite->invite_uid != $uid) {
  602. throw new AlertException("权限不足", 403);
  603. }
  604. if ($invite->state == 1) {
  605. throw new AlertException("参数错误", 422);
  606. }
  607. \DB::beginTransaction();
  608. try {
  609. $invite->read = time();
  610. $invite->state = $state;
  611. \DB::commit();
  612. if ($state == 1) {
  613. $invite->send_read = 0;
  614. $invite->receive_at = time();
  615. $invite->save();
  616. $fs = new FriendService();
  617. $fs->befriend($invite->uid, $invite->invite_uid, 1, $invite->id);
  618. try {
  619. $ns = new NoticeService();
  620. $ns->invitationSuccess($invite->uid, $invite->invite_uid);
  621. } catch (\Exception $exception) {
  622. app('sentry')->captureException($exception);
  623. }
  624. } else {
  625. $invite->save();
  626. }
  627. return true;
  628. } catch (\Exception $exception) {
  629. \DB::rollBack();
  630. throw $exception;
  631. }
  632. }
  633. /**
  634. * 阅读 邀请
  635. * @param int $invite_id
  636. * @param int $uid
  637. * @return bool
  638. * @throws AlertException
  639. */
  640. public function fixread(int $invite_id, int $uid)
  641. {
  642. $icm = new InvitationCardModel();
  643. $invite = $icm->findOrFail($invite_id);
  644. if (!in_array($uid, [$invite->invite_uid, $invite->uid])) {
  645. throw new AlertException("权限不足", 403);
  646. }
  647. if ($invite->read == 0 && $invite->invite_uid == $uid) {
  648. $invite->read = time();
  649. $invite->save();
  650. return true;
  651. }
  652. if ($invite->send_read == 0 && $invite->uid == $uid) {
  653. $invite->send_read = time();
  654. $invite->save();
  655. return true;
  656. }
  657. return true;
  658. }
  659. /**
  660. * 获取某人当前邀请数量
  661. * @param int $uid
  662. * @return array
  663. */
  664. public function invitecnt(int $uid)
  665. {
  666. $total = InvitationCardModel::where('invite_uid', $uid)->count();
  667. $ings = InvitationCardModel::where([
  668. ['invite_uid', $uid],
  669. ['state', 0],
  670. ['expired_at', '>', time()],
  671. ])->count();
  672. return array(
  673. 'total' => $total,
  674. 'ings' => $ings,
  675. );
  676. }
  677. }