OldUserNoticeCommand.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace App\Console\Commands\Notices;
  3. use App\Models\Fpdx\PairModel;
  4. use App\Models\PartnerModel;
  5. use App\Services\Partner\NoticeService;
  6. use Illuminate\Console\Command;
  7. class OldUserNoticeCommand extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'notice:old_user {notice}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '老用户-通知';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $notice = $this->argument('notice');
  38. \DB::connection()->enableQueryLog(); // 开启查询日志
  39. switch ($notice) {
  40. case "vip":
  41. dump($this->vip());
  42. break;
  43. case "once_pair":
  44. dump($this->oncePair());
  45. break;
  46. case "phone_not_card":
  47. dump($this->phoneNotCard());
  48. break;
  49. case "partner":
  50. dump($this->partner());
  51. break;
  52. case "visitor":
  53. dump($this->visitorCallBack());
  54. break;
  55. case 'cardRecommendCancel':
  56. dump($this->cardRecommendCancel());
  57. break;
  58. case "syj_pair1":
  59. dump($this->syj_pair1());
  60. break;
  61. case 'syj_pair2':
  62. dump($this->syj_pair2());
  63. break;
  64. case 'syj_visitor':
  65. dump($this->syj_visitor());
  66. break;
  67. case 'syj_like':
  68. dump($this->syj_like());
  69. break;
  70. case 'syj_like2':
  71. dump($this->syj_like2());
  72. break;
  73. }
  74. $queries = \DB::getQueryLog(); // 获取查询日志
  75. print_r($queries);
  76. }
  77. /**
  78. * 老用户召回-激活会员通知
  79. */
  80. public function vip()
  81. {
  82. // 过滤发送过的人
  83. $filter_users = \DB::connection('mysql_datalog')
  84. ->table("notice_logs")
  85. ->where('title', '老用户召回-激活会员通知')
  86. ->pluck('uid')->toArray();
  87. // 关注公众号、未开通会员
  88. $users = \DB::table('kddx_user_openid as o')
  89. ->select('u.uid')
  90. ->join('kdgx_partner_charge_user as u', 'u.uid', '=', 'o.uid')
  91. ->where('u.be_vip_at', 0)
  92. ->where('o.public_id', 'gh_b598cb7474d8')
  93. ->where('o.subscribe', 1)
  94. ->whereNotIn('u.uid', $filter_users)
  95. ->orderBy('u.uid')
  96. ->limit(180)
  97. ->get();
  98. foreach ($users as $user) {
  99. $uid = $user->uid;
  100. $notification = new \App\Services\User\Notifications\OldUserToVipNotification($uid);
  101. $notification->send();
  102. }
  103. return $users;
  104. }
  105. /**
  106. * 有手机号但无卡片者通知
  107. * @return \Illuminate\Support\Collection
  108. */
  109. public function phoneNotCard()
  110. {
  111. $filter_users = \DB::connection('mysql_datalog')
  112. ->table("notice_logs")
  113. ->where('title', '老用户召回-有手机号但无卡片者通知')
  114. ->pluck('uid')
  115. ->toArray();
  116. $users = \DB::table('kddx_user_openid as o')
  117. ->select('u.uid')
  118. ->join('kdgx_partner_charge_user as u', 'u.uid', '=', 'o.uid')
  119. ->where('u.partner_id', 0)
  120. ->whereNotNull('phone')
  121. ->where('o.public_id', 'gh_b598cb7474d8')
  122. ->where('o.subscribe', 1)
  123. ->whereNotIn('u.uid', $filter_users)
  124. ->orderBy('u.uid', 'desc')
  125. ->limit(60)
  126. ->get();
  127. foreach ($users as $user) {
  128. // 模版消息
  129. $notification = new \App\Services\User\Notifications\OldUserToNotCardNotification($user->uid);
  130. $notification->send();
  131. }
  132. return $users;
  133. }
  134. /**
  135. *
  136. */
  137. public function oncePair()
  138. {
  139. $filter_users = \DB::connection('mysql_datalog')
  140. ->table("notice_logs")
  141. ->where('title', '老用户召回-仅参与过一次活动的用户')
  142. ->pluck('uid')
  143. ->toArray();
  144. $users = \DB::table('kddx_user_openid as o')
  145. ->select('u.uid')
  146. ->join('kdgx_partner_charge_user as u', 'u.uid', '=', 'o.uid')
  147. ->where('o.public_id', 'gh_b598cb7474d8')
  148. ->where('o.subscribe', 1)
  149. ->whereNull('u.phone')
  150. ->whereNotIn("u.uid", $filter_users)
  151. ->whereRaw("u.uid in (SELECT `uid`
  152. FROM `koudai`.`kdgx_partner_charge_pair`
  153. WHERE `create_time`> 1541001600
  154. GROUP BY `uid`
  155. HAVING COUNT(*)= 1)")
  156. ->limit(120)
  157. ->get();
  158. foreach ($users as $user) {
  159. // 模版消息
  160. $notification = new \App\Services\User\Notifications\OldUserToOncePairNotification($user->uid);
  161. $notification->send();
  162. }
  163. return $users;
  164. }
  165. public function partner()
  166. {
  167. $filter_users = \DB::connection('mysql_datalog')
  168. ->table("notice_logs")
  169. ->where('title', '老用户召回-有卡片的用户')
  170. ->pluck('uid')
  171. ->toArray();
  172. $users = \DB::table('kddx_user_openid as o')
  173. ->select('u.uid')
  174. ->join('kdgx_partner_charge_user as u', 'u.uid', '=', 'o.uid')
  175. ->where('u.partner_id', '>', 0)
  176. ->where('o.public_id', 'gh_b598cb7474d8')
  177. ->where('o.subscribe', 1)
  178. ->whereBetween('u.login_at', [time() - 6 * 86400, time() - 5 * 86400])
  179. ->whereNotIn("u.uid", $filter_users)
  180. ->limit(600)
  181. ->get();
  182. foreach ($users as $user) {
  183. // 模版消息
  184. $notification = new \App\Services\User\Notifications\OldUserToPartnerNotification($user->uid);
  185. $notification->send();
  186. }
  187. return $users;
  188. }
  189. // 服务号召回通知-通过访客召回
  190. public function visitorCallBack()
  191. {
  192. // 过滤发送过的人
  193. $filter_users = \DB::connection('mysql_datalog')
  194. ->table("notice_logs")
  195. ->where('title', '老用户召回-访客通知')
  196. ->pluck('uid');
  197. $users = \DB::table('kddx_user_openid as o')
  198. ->select('p.uid')
  199. ->join('kdgx_partner_charge_partner as p', 'p.uid', '=', 'o.uid')
  200. ->where('p.id', '>', 0)
  201. ->where('p.is_sell', 1)
  202. ->where('o.public_id', 'gh_b598cb7474d8')
  203. ->where('o.subscribe', 1)
  204. ->where('p.login_at', '<', strtotime("-1 month"))
  205. ->whereNotIn('p.uid', $filter_users)
  206. ->limit(600)
  207. ->get();
  208. foreach ($users as $user) {
  209. // 模版消息
  210. $notification = new \App\Services\User\Notifications\OldUserToVisitorNotification($user->uid);
  211. $notification->send();
  212. }
  213. return $users;
  214. }
  215. /**
  216. * 卡片取消推荐未换卡片,每日都推
  217. */
  218. public function cardRecommendCancel()
  219. {
  220. // 过滤一周内发送过的人
  221. $begin = mktime(0, 0, 0) - 7 * 86400;
  222. $end = time();
  223. $filter_users = \DB::connection('mysql_datalog')
  224. ->table("notice_logs")
  225. ->where('title', '交友卡片-卡片取消推荐未更换通知')
  226. ->whereBetween('created_at', [$begin, $end])
  227. ->pluck('uid');
  228. $cards = PartnerModel::select('uid')
  229. ->where('is_push_feed', 0)
  230. ->whereNotIn('uid', $filter_users)
  231. ->limit(1000)
  232. ->pluck('uid');
  233. foreach ($cards as $uid) {
  234. (new NoticeService())->recommendCancelNotChange($uid);
  235. }
  236. }
  237. }