OldUserRetainedService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Services\Notice;
  3. use App\Models\Deed\InvitationCardModel;
  4. use App\Models\Log\FeedLogModel;
  5. use App\Models\PraiseModel;
  6. use App\Models\User\UserModel;
  7. use App\Services\QQMiniApp\Template;
  8. use App\Services\Service;
  9. class OldUserRetainedService extends Service
  10. {
  11. public function send()
  12. {
  13. $users = UserModel::whereBetween(
  14. 'login_at',
  15. [mktime(0, 0, 0) - 3 * 86400, mktime(0, 0, 0)]
  16. )->where('partner_id', '>', 0)->get([
  17. 'uid',
  18. 'partner_id',
  19. 'sex',
  20. ]);
  21. foreach ($users as $user) {
  22. $this->qqNotice($user);
  23. }
  24. }
  25. public function qqNotice($user)
  26. {
  27. $cnt = FeedLogModel::where('partner_id', $user->partner_id)->whereBetween(
  28. 'created_at',
  29. [mktime(0, 0, 0) - 86400, mktime(0, 0, 0)]
  30. )->count();
  31. if ($cnt <= 0) {
  32. return;
  33. }
  34. $sex = "小哥哥";
  35. 1 == $user->sex && $sex = "小姐姐";
  36. $content = "昨天共有{$cnt}个{$sex}访问了你的主页";
  37. $thumbs = PraiseModel::where(array(['partner_id', $user->partner_id], ['type', 1]))->whereBetween(
  38. 'create_at',
  39. [mktime(0, 0, 0) - 86400, mktime(0, 0, 0)]
  40. )->count();
  41. $invites = InvitationCardModel::where("invite_uid", $user->uid)->whereBetween(
  42. 'created_at',
  43. [mktime(0, 0, 0) - 86400, mktime(0, 0, 0)]
  44. )->count();
  45. if ($thumbs > 0 || $invites > 0) {
  46. if ($thumbs > 0) {
  47. $content = $content . ",共收到了{$thumbs}个「心动」";
  48. }
  49. if ($invites > 0) {
  50. $content = $content . ",{$invites}个「心动邀请」";
  51. }
  52. } else {
  53. $rands = array(
  54. ",其中有" . rand(1, $cnt / 2) . "个人为你停留了20秒以上",
  55. ",有" . rand(1, $cnt / 2) . "个人距离你不到1km哦~",
  56. );
  57. $content = $content . $rands[rand(0, 1)];
  58. }
  59. $title = "QQ小程序留存通知";
  60. $page = "popularity/pages/watched/watched";
  61. $app = new Template(config("qqprogram.app_id"));
  62. $app->setTitle($title)
  63. ->setUuid(uuid())
  64. ->toUser($user->uid)
  65. ->setPage($page)
  66. ->setParameters([
  67. 'keyword1' => array(
  68. 'value' => "人气值日报",
  69. ),
  70. 'keyword2' => array(
  71. 'value' => $content,
  72. ),
  73. 'keyword3' => array(
  74. 'value' => "今日推荐已更新,小象为你匹配了56个兴趣相投又好看的{$sex},说不定其中就有你心动的人哦!",
  75. ),
  76. ])
  77. ->setTemplateId("97888863d45a37a7ef08e5e1aedfbfe1")
  78. ->send();
  79. }
  80. }