BuyInvite.php 4.0 KB

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