QQCommand.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. namespace App\Console\Commands\Notices;
  3. use App\Managers\CouponManager;
  4. use App\Models\Log\FeedLogModel;
  5. use App\Models\NoticeModel;
  6. use App\Models\PartnerModel;
  7. use App\Models\User\AuthKey;
  8. use App\Services\NoticeService\Channels\QQMiniTemplateChannel;
  9. use App\Services\Pay\CouponService;
  10. use App\Services\QQMiniApp\Template;
  11. use Illuminate\Console\Command;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Redis;
  14. class QQCommand extends Command
  15. {
  16. /**
  17. * The name and signature of the console command.
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'notice:qq {notice}';
  22. /**
  23. * The console command description.
  24. *
  25. * @var string
  26. */
  27. protected $description = '通知-QQ小程序营销通知';
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. }
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return mixed
  41. */
  42. public function handle()
  43. {
  44. $notice = $this->argument('notice');
  45. switch ($notice) {
  46. case "first":
  47. dump($this->first());
  48. break;
  49. case "second":
  50. dump($this->second());
  51. break;
  52. case "third":
  53. dump($this->third());
  54. break;
  55. }
  56. }
  57. // 通知-QQ小程序老用户召回:第1条
  58. public function first()
  59. {
  60. $title = 'QQ小程序老用户召回-第1条';
  61. $filter_users = DB::connection('mysql_datalog')
  62. ->table("notice_logs")
  63. ->where([
  64. ['title', $title]
  65. ])
  66. ->pluck('uid')->toArray();
  67. $redis = Redis::Smembers("qq:olduser:callback:1");
  68. array_walk($redis, function (&$value) use ($filter_users) {
  69. $value = intval($value);
  70. array_push($filter_users, $value);
  71. });
  72. $sat = mktime(0, 0, 0) - 5 * 86400;
  73. $users = PartnerModel::whereBetween("login_at", [$sat, $sat + 86400])
  74. ->where('is_sell', 1)->whereNotIn('uid', $filter_users)->take(600)->get(['id', 'uid', 'sex', 'login_at']);
  75. foreach ($users as $user) {
  76. try {
  77. $sex = "小姐姐";
  78. $ta = "她";
  79. 2 == $user->sex && $sex = "小哥哥";
  80. 2 == $user->sex && $ta = "他";
  81. $cnt = FeedLogModel::where([
  82. ['partner_id', $user->id],
  83. ['created_at', '>', $user->login_at]
  84. ])->count() + 1;
  85. $templates = array(
  86. [
  87. 'template_id' => '8a4e8c0f73be381f49935dd20d79b6b9',
  88. 'data' => [
  89. 'keyword1' => array(
  90. 'value' => "刚才有一位{$sex}反复查看了你的个人主页。{$ta}离你只有0." . rand(1, 9) . "km哦!"
  91. ),
  92. 'keyword2' => array(
  93. 'value' => "快来划卡片找到{$ta}~"
  94. ),
  95. 'keyword3' => array(
  96. 'value' => "{$cnt}"
  97. )
  98. ]
  99. ]
  100. );
  101. $template = $templates[rand(0, count($templates) - 1)];
  102. $page = "/pages/starter/starter";
  103. $app = new Template(config("qqprogram.app_id"));
  104. $app->setTitle($title)
  105. ->setUuid(uuid())
  106. ->setParameters($template['data'])
  107. ->setTemplateId($template['template_id'])
  108. ->toUser($user->uid)
  109. ->setPage($page)
  110. ->send();
  111. Redis::sadd("qq:olduser:callback:1", $user->uid);
  112. } catch (\Exception $exception) {
  113. }
  114. }
  115. Redis::expire("qq:olduser:callback:1", 86400);
  116. return true;
  117. }
  118. // 通知-QQ小程序老用户召回:第2条
  119. public function second()
  120. {
  121. $title = 'QQ小程序老用户召回-第2条';
  122. $filter_users = DB::connection('mysql_datalog')
  123. ->table("notice_logs")
  124. ->where([
  125. ['title', $title]
  126. ])
  127. ->pluck('uid')->toArray();
  128. $redis = Redis::Smembers("qq:olduser:callback:2");
  129. array_walk($redis, function (&$value) use ($filter_users) {
  130. $value = intval($value);
  131. array_push($filter_users, $value);
  132. });
  133. $sat = mktime(0, 0, 0) - 6 * 86400;
  134. $users = PartnerModel::whereBetween("login_at", [$sat, $sat + 86400])
  135. ->where('is_sell', 1)->whereNotIn('uid', $filter_users)->take(600)->get(['id', 'uid', 'sex', 'login_at']);
  136. foreach ($users as $user) {
  137. try {
  138. $sex = "小姐姐";
  139. $ta = "她";
  140. 2 == $user->sex && $sex = "小哥哥";
  141. 2 == $user->sex && $ta = "他";
  142. $templates = array(
  143. [
  144. 'template_id' => '8a4e8c0f73be381f49935dd20d79b6b9',
  145. 'data' => [
  146. 'keyword1' => array(
  147. 'value' => "有一个距你0." . rand(1, 9) . "km的{$sex}喜欢了你,一直等不到你的回应…"
  148. ),
  149. 'keyword2' => array(
  150. 'value' => "{$ta}曾收到过" . rand(101, 626) . "个喜欢"
  151. ),
  152. 'keyword3' => array(
  153. 'value' => "快来划卡片找到{$ta}~"
  154. )
  155. ]
  156. ]
  157. );
  158. $template = $templates[rand(0, count($templates) - 1)];
  159. $page = "/pages/starter/starter";
  160. $app = new Template(config("qqprogram.app_id"));
  161. $app->setTitle($title)
  162. ->setUuid(uuid())
  163. ->setParameters($template['data'])
  164. ->setTemplateId($template['template_id'])
  165. ->toUser($user->uid)
  166. ->setPage($page)
  167. ->send();
  168. Redis::sadd("qq:olduser:callback:2", $user->uid);
  169. } catch (\Exception $exception) {
  170. }
  171. }
  172. Redis::expire("qq:olduser:callback:2", 86400);
  173. return $users;
  174. }
  175. // 通知-QQ小程序老用户召回:第3条
  176. public function third()
  177. {
  178. $title = 'QQ小程序老用户召回-第3条';
  179. $filter_users = DB::connection('mysql_datalog')
  180. ->table("notice_logs")
  181. ->where([['title', $title], ['result', 1]])
  182. ->pluck('uid')->toArray();
  183. $redis = Redis::Smembers("qq:olduser:callback:3");
  184. array_walk($redis, function (&$value) use ($filter_users) {
  185. $value = intval($value);
  186. array_push($filter_users, $value);
  187. });
  188. $sat = mktime(0, 0, 0) - 7 * 86400;
  189. $users = PartnerModel::whereBetween("login_at", [$sat, $sat + 86400])
  190. ->where('is_sell', 1)->whereNotIn('uid', $filter_users)->take(600)->get(['uid']);
  191. foreach ($users as $user) {
  192. try {
  193. $sex = "小姐姐";
  194. 2 == $user->sex && $sex = "小哥哥";
  195. $templates = array(
  196. [
  197. 'template_id' => '8a4e8c0f73be381f49935dd20d79b6b9',
  198. 'data' => [
  199. 'keyword1' => array(
  200. 'value' => "有一个{$sex}想邀请你参加72小时恋爱体验活动~"
  201. ),
  202. 'keyword2' => array(
  203. 'value' => "你们将组成CP,一起度过奇妙的72小时"
  204. ),
  205. 'keyword3' => array(
  206. 'value' => "小象送你一张免费报名券,祝你顺利~"
  207. )
  208. ]
  209. ]
  210. );
  211. $template = $templates[rand(0, count($templates) - 1)];
  212. $page = "/pages/starter/starter";
  213. $app = new Template(config("qqprogram.app_id"));
  214. $app->setTitle($title)
  215. ->setUuid(uuid())
  216. ->setParameters($template['data'])
  217. ->setTemplateId($template['template_id'])
  218. ->toUser($user->uid)
  219. ->setPage($page)
  220. ->send();
  221. if (0 == $app->getCode()) {
  222. $couponManager = new CouponManager();
  223. $couponManager->generateSuperVip72FreeCoupons($user->uid);
  224. NoticeModel::create([
  225. 'uid' => $user->uid,
  226. 'title' => '如何使用“72小时恋爱体验”券报名',
  227. 'content' => "恭喜你中奖获得“72小时恋爱体验”券1张!点此教你如何使用体验券免费报名活动,直升最高匹配成功率!助力脱单~",
  228. 'type' => 5,
  229. 'type_id' => 0,
  230. 'create_at' => time(),
  231. 'update_at' => time(),
  232. 'tab_content' => '查看详情',
  233. 'tab_url' => 'https://mp.weixin.qq.com/s/mba8TwZP9dNYY0E2XF24wg',
  234. ]);
  235. }
  236. Redis::sadd("qq:olduser:callback:3", $user->uid);
  237. } catch (\Exception $exception) {
  238. }
  239. }
  240. Redis::expire("qq:olduser:callback:3", 86400);
  241. return $users;
  242. }
  243. public function tmp()
  244. {
  245. $auths = AuthKey::where('auth_type', '1109365561')->get();
  246. foreach ($auths as $auth) {
  247. $app = new QQMiniTemplateChannel();
  248. $app->setAppId("1109365561")->toUser($auth->auth_key)
  249. ->setTitle("QQ小程序用户72h运营通知")
  250. ->setTemplateId("d149209e80157fd6e340a8049f7c02b7")
  251. ->setParameters([
  252. 'keyword1' => array(
  253. 'value' => "你有一条「约会」邀请信息~"
  254. ),
  255. 'keyword2' => array(
  256. 'value' => "本周四12:00前"
  257. ),
  258. 'keyword3' => array(
  259. 'value' => "假期太无聊,不想再打发时间?那...要不要和我恋爱约会呢,一起度过愉快的三天?点此报名72小时恋爱体验活动,接受「约会」邀请"
  260. )
  261. ])->setPage("pages/starter/starter?launch_type=fpdx")
  262. ->send();
  263. }
  264. }
  265. }