BuyInvite.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Controllers\Core\Auth;
  4. use App\Models\BuyInviteListModel;
  5. use App\Models\BuyInviteModel;
  6. use App\Models\RecodeModel;
  7. use App\Models\PartnerModel;
  8. use App\Services\Share\LockService;
  9. class BuyInvite extends Controller
  10. {
  11. /**
  12. * 获取邀请信息
  13. * @param int $invite_id
  14. * @return array
  15. * @throws \ApiException
  16. */
  17. public function get(int $invite_id)
  18. {
  19. $invite = BuyInviteListModel::find($invite_id);
  20. if (collect($invite)->isEmpty()) {
  21. return array(
  22. 'code' => 101,
  23. 'message' => '参数错误'
  24. );
  25. } else {
  26. return array(
  27. 'code' => 200,
  28. 'message' => 'success',
  29. 'data' => [
  30. 'uid' => $invite->uid,
  31. 'cnt' => $invite->effectiveInvite($invite_id),
  32. ],
  33. );
  34. }
  35. }
  36. /**
  37. * 解锁助力邀请检验
  38. * @param int $invite_id
  39. * @return array
  40. * @throws \ApiException
  41. * @throws \App\Exceptions\ApiException
  42. * @throws \App\Exceptions\DBException
  43. * @throws \Throwable
  44. */
  45. public function invite(int $invite_id)
  46. {
  47. $uid = Auth::auth();
  48. $ls = new LockService();
  49. $data = $ls->check($uid, $invite_id);
  50. return array(
  51. 'code' => 200,
  52. 'message' => 'success',
  53. 'data' => $data
  54. );
  55. }
  56. public function sync()
  57. {
  58. $comment = array(
  59. '希望这世界上从此少一个单身狗',
  60. '希望你不在是一个人过',
  61. '祝脱单',
  62. '成了别忘了发红包',
  63. '等着吃你的喜糖',
  64. '直觉告诉我,你这次要脱单',
  65. '坐等吃狗粮',
  66. '我已经准备好,喝喜酒的红包',
  67. '你这波突然袭击,很skr',
  68. '单身的终点,浪漫的节点,幸福的起点',
  69. '从此后,天更蓝,月更圆,你对未来有了更多期盼',
  70. '单薄的爱情填不满宽阔的岁月,你终于有长进了',
  71. '这波操作很骚',
  72. '大吉大利,今晚脱单',
  73. '请接收我1w点的助力暴击',
  74. '行动才是脱单的纲领,你做到了',
  75. '赶紧脱单,我是认真的,一秒钟都不许你浪费',
  76. '我很介意你单身,so赶紧脱单',
  77. '明天,我希望可以给你发来脱单贺电',
  78. '我感受到爱情的航班在呼唤你',
  79. '有种,有种,有种你现在就给我丢1w斤的狗粮'
  80. );
  81. $listModel = new BuyInviteListModel();
  82. $lists = $listModel->get();
  83. foreach ($lists as $list) {
  84. $recode = new RecodeModel();
  85. if (
  86. $recode->where([
  87. ['partner_id', $list->partner_id],
  88. ['uid', $list->uid]
  89. ])->exists()
  90. ) {
  91. $invModel = new BuyInviteModel();
  92. $invites = $invModel->where('invite_id', $list->id)->get();
  93. $cnt = $invites->count();
  94. $dis_score = floor(100 / $cnt);
  95. $invModel->whereIn('id', $invites->pluck('id'))->update([
  96. 'dis_score' => $dis_score,
  97. 'comment' => $comment[rand(0, 20)]
  98. ]);
  99. } else {
  100. $partner = PartnerModel::find($list->partner_id);
  101. $total = $partner->charm > 9 ? 9 : $partner->charm;
  102. $invModel = new BuyInviteModel();
  103. $invites = $invModel->where('invite_id', $list->id)->get();
  104. $dis_score = floor(100 / $total);
  105. $invModel->whereIn('id', $invites->pluck('id'))->update([
  106. 'dis_score' => $dis_score,
  107. 'comment' => $comment[rand(0, 20)]
  108. ]);
  109. }
  110. }
  111. }
  112. }