FpdxCommand.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. namespace App\Console\Commands\Notices;
  3. use App\Services\NoticeService\Channels\WeChatTemplateChannel;
  4. use Illuminate\Console\Command;
  5. class FpdxCommand extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'notice:fpdx {notice}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '分配对象公众号营销通知';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. public const PUBLIC_ID = 'gh_b598cb7474d8';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $notice = $this->argument('notice');
  37. \DB::connection()->enableQueryLog(); // 开启查询日志
  38. switch ($notice) {
  39. case 'a':
  40. dump($this->card1());
  41. break;
  42. case 'b':
  43. dump($this->card2());
  44. break;
  45. case 'c':
  46. dump($this->card3());
  47. break;
  48. }
  49. $queries = \DB::getQueryLog(); // 获取查询日志
  50. dump($queries);
  51. }
  52. /*
  53. * 关注公众号、无卡片ID/有卡片ID(无照片&无语音&无联系方式)
  54. * @return bool
  55. */
  56. public function card1()
  57. {
  58. $title = "老用户召回fpdx-卡片1";
  59. if (
  60. \DB::connection('mysql_datalog')
  61. ->table("notice_logs")
  62. ->where('title', $title)
  63. ->where('date', date("Y-m-d"))
  64. ->count() >= 3000
  65. ) {
  66. return false;
  67. }
  68. // 过滤发送过的人
  69. $filter_users = \DB::connection('mysql_datalog')
  70. ->table("notice_logs")
  71. ->where('title', $title)
  72. ->distinct()
  73. ->pluck('openid');
  74. $users = \DB::table('kddx_user_openid as o')
  75. ->select('o.openid', 'o.sex')
  76. ->leftjoin("kdgx_partner_charge_partner as p", function ($join) {
  77. $join->on('o.uid', '=', 'p.uid')
  78. ->whereRaw(" (p.`photo_src`!= ''
  79. or p.`photo_1`!= ''
  80. or p.`photo_2`!= ''
  81. or p.`photo_3`!= ''
  82. or p.`photo_4`!= ''
  83. or p.`voice`!= ''
  84. or p.`weixin` is NOT null
  85. or p.`qq` IS NOT NULL)");
  86. })
  87. ->whereNull('p.id')
  88. ->where('o.public_id', self::PUBLIC_ID)
  89. ->where('o.subscribe', 1)
  90. ->whereNotIn('o.openid', $filter_users)
  91. ->orderBy('o.id', 'desc')
  92. ->limit(rand(1, 5))
  93. ->get();
  94. foreach ($users as $user) {
  95. switch ($user->sex) {
  96. case '1':
  97. $ta = '小姐姐';
  98. break;
  99. case '2':
  100. $ta = '小哥哥';
  101. break;
  102. default:
  103. $ta = '新朋友';
  104. break;
  105. }
  106. $templates = [
  107. [
  108. 'template_id' => '9e-Aclq7-z-BpMxfbFl-PnnePPoPJvdAmAYoZv2MCHw',
  109. 'data' => [
  110. 'first' => [
  111. 'value' => "小遇今日为你精选了56个兴趣相投又好看的{$ta}。说不定其中就有你心动的人哦!",
  112. ],
  113. 'keyword1' => [
  114. 'value' => date('Y-m-d')
  115. ],
  116. 'keyword2' => [
  117. 'value' => '精选推荐',
  118. ],
  119. 'keyword3' => [
  120. 'value' => '已推荐',
  121. ],
  122. 'remark' => [
  123. 'value' => "他们之中离你最近的只有0.5km哦~",
  124. ]
  125. ]
  126. ],
  127. [
  128. 'template_id' => 'aWsSfsy-EalI_jzopvZhjImLQkjIK1qVZqIbhMvY-4o',
  129. 'data' => [
  130. 'first' => [
  131. 'value' => "小遇今日为你精选了56个兴趣相投又好看的{$ta}。说不定其中就有你心动的人哦!",
  132. ],
  133. 'keyword1' => [
  134. 'value' => '小遇',
  135. ],
  136. 'keyword2' => [
  137. 'value' => '推荐提醒',
  138. ],
  139. 'remark' => [
  140. 'value' => "他们之中离你最近的只有0.5km哦~",
  141. ]
  142. ]
  143. ]
  144. ];
  145. $rand = rand(0, count($templates) - 1);
  146. $templateId = $templates[$rand]['template_id'];
  147. $parameters = $templates[$rand]['data'];
  148. $page = "pages/index/index";
  149. $weChatTemplate = new WeChatTemplateChannel();
  150. $weChatTemplate->setAppId(self::PUBLIC_ID)
  151. ->setTitle($title)
  152. ->toUser($user->openid)
  153. ->setPage($page)
  154. ->setTemplateId($templateId)
  155. ->setParameters($parameters)
  156. ->send();
  157. }
  158. return ($users);
  159. }
  160. /**
  161. * 关注服务号,有卡片信息(照片or语音),未上架的用户
  162. * @return bool
  163. */
  164. public function card2()
  165. {
  166. $title = "老用户召回fpdx-卡片2";
  167. if (
  168. \DB::connection('mysql_datalog')
  169. ->table("notice_logs")
  170. ->where('title', $title)
  171. ->where('date', date("Y-m-d"))
  172. ->count() >= 3000
  173. ) {
  174. return false;
  175. }
  176. // 过滤发送过的人
  177. $filter_users = \DB::connection('mysql_datalog')
  178. ->table("notice_logs")
  179. ->where('title', $title)
  180. ->distinct()
  181. ->pluck('openid');
  182. $users = \DB::table('kddx_user_openid as o')
  183. ->select('o.openid', 'o.nickname')
  184. ->join("kdgx_partner_charge_partner as p", function ($join) {
  185. $join->on('o.uid', '=', 'p.uid');
  186. })
  187. ->where('o.public_id', self::PUBLIC_ID)
  188. ->where('o.subscribe', 1)
  189. ->whereRaw(" (p.`photo_src`!= ''
  190. or p.`photo_1`!= ''
  191. or p.`photo_2`!= ''
  192. or p.`photo_3`!= ''
  193. or p.`photo_4`!= ''
  194. or p.`voice`!= ''
  195. )")
  196. ->where('p.is_sell', '<>', 1)
  197. ->whereNotIn('o.openid', $filter_users)
  198. ->orderBy('o.id', 'desc')
  199. ->limit(rand(1, 5))
  200. ->get();
  201. foreach ($users as $user) {
  202. $x = rand(100, 1000);
  203. $templates = [
  204. [
  205. 'template_id' => 'JVICUmaP38MoputCdKVn5AAIFmc7ZO9eewj2FyW58NM',
  206. 'data' => [
  207. 'first' => [
  208. 'value' => "你的交友卡片尚未修改或完善,已错过{$x}次推荐曝光机会",
  209. ],
  210. 'keyword1' => [
  211. 'value' => '交友卡片待完善',
  212. ],
  213. 'keyword2' => [
  214. 'value' => date("Y-m-d"),
  215. ],
  216. 'remark' => [
  217. 'value' => "点此继续完善卡片重新提交审核,通过后将优先把你推荐给附近的人",
  218. ]
  219. ]
  220. ],
  221. [
  222. 'template_id' => 'vj03Lys62tcWH0BAx2bKdDbzxBnhwe4Fhs3GXqbxkTg',
  223. 'data' => [
  224. 'first' => [
  225. 'value' => "你的交友卡片尚未修改或完善,已错过{$x}次推荐曝光机会",
  226. ],
  227. 'keyword1' => [
  228. 'value' => '交友卡片待完善',
  229. ],
  230. 'keyword2' => [
  231. 'value' => date("Y-m-d"),
  232. ],
  233. 'remark' => [
  234. 'value' => "点此继续完善卡片重新提交审核,通过后将优先把你推荐给附近的人",
  235. ]
  236. ]
  237. ]
  238. ];
  239. $rand = rand(0, count($templates) - 1);
  240. $templateId = $templates[$rand]['template_id'];
  241. $parameters = $templates[$rand]['data'];
  242. $page = "pages/my-friend-card-editor/my-friend-card-editor";
  243. $weChatTemplate = new WeChatTemplateChannel();
  244. $weChatTemplate->setAppId(self::PUBLIC_ID)
  245. ->setTitle($title)
  246. ->toUser($user->openid)
  247. ->setPage($page)
  248. ->setTemplateId($templateId)
  249. ->setParameters($parameters)
  250. ->send();
  251. }
  252. return $users;
  253. }
  254. /**
  255. * 关注服务号,有交友卡片,超1月未登录
  256. * @return bool
  257. */
  258. public function card3()
  259. {
  260. $title = "老用户召回-访客通知";
  261. if (
  262. \DB::connection('mysql_datalog')
  263. ->table("notice_logs")
  264. ->where('title', $title)
  265. ->where('date', date("Y-m-d"))
  266. ->count() >= 3000
  267. ) {
  268. return false;
  269. }
  270. // 过滤发送过的人
  271. $filter_users = \DB::connection('mysql_datalog')
  272. ->table("notice_logs")
  273. ->where('title', $title)
  274. ->distinct()
  275. ->pluck('openid');
  276. // 关注公众号、有手机号、登陆时间为一个月之前的人
  277. // 仅参加一次活动
  278. $users = \DB::table('kddx_user_openid as o')
  279. ->select('o.openid', 'o.nickname', 'o.sex')
  280. ->join('kdgx_partner_charge_user as u', 'o.uid', '=', 'u.uid')
  281. ->where('u.login_at', '<', strtotime("-1 month"))
  282. ->where('o.public_id', self::PUBLIC_ID)
  283. ->where('o.subscribe', 1)
  284. ->whereNotIn('o.openid', $filter_users)
  285. ->orderBy('o.id', 'desc')
  286. ->limit(rand(1, 5))
  287. ->get();
  288. foreach ($users as $user) {
  289. $x = rand(100, 1000);
  290. switch ($user->sex) {
  291. case '1':
  292. $ta = '小姐姐';
  293. break;
  294. case '2':
  295. $ta = '小哥哥';
  296. break;
  297. default:
  298. $ta = '小姐姐';
  299. break;
  300. }
  301. $templates = [
  302. [
  303. 'template_id' => 'buiSCGP-jKweNEVi7V8ZK-8Lspem1FopbD5Kvupg1Ig',
  304. 'data' => [
  305. 'first' => [
  306. 'value' => "\n你不在的这段时间里,已经有{$x}个{$ta}看过你的交友卡片了!快来看看都有哪些人吧~\n"
  307. ],
  308. 'keyword1' => [
  309. 'value' => "访客通知"
  310. ],
  311. 'keyword2' => [
  312. 'value' => "已通知"
  313. ],
  314. 'keyword3' => [
  315. 'value' => date('Y-m-d')
  316. ],
  317. 'keyword4' => [
  318. 'value' => "分配对象个人中心"
  319. ],
  320. 'remark' => [
  321. 'value' => "\n他们之中离你最近的只有0.5km哦,来看看你附近的{$ta}吧~ ",
  322. ],
  323. ]
  324. ],
  325. [
  326. 'template_id' => 'ugxHaIxl5sFf2T00QZdCc0l4qELRUfEtw1HnCE7PDww',
  327. 'data' => [
  328. 'first' => [
  329. 'value' => "\n你不在的这段时间里,已经有{$x}个{$ta}看过你的交友卡片了!快来看看都有哪些人吧~\n"
  330. ],
  331. 'keyword1' => [
  332. 'value' => "访客通知"
  333. ],
  334. 'keyword2' => [
  335. 'value' => "分配对象个人中心"
  336. ],
  337. 'keyword3' => [
  338. 'value' => "访客通知"
  339. ],
  340. 'keyword4' => [
  341. 'value' => date('Y-m-d')
  342. ],
  343. 'remark' => [
  344. 'value' => "\n他们之中离你最近的只有0.5km哦,来看看你附近的{$ta}吧~ ",
  345. ],
  346. ]
  347. ],
  348. [
  349. 'template_id' => 'vj03Lys62tcWH0BAx2bKdDbzxBnhwe4Fhs3GXqbxkTg',
  350. 'data' => [
  351. 'first' => [
  352. 'value' => "你不在的这段时间里,已经有{$x}个{$ta}看过你的交友卡片了!快来看看都有哪些人吧~\n"
  353. ],
  354. 'keyword1' => [
  355. 'value' => "访客通知"
  356. ],
  357. 'keyword2' => [
  358. 'value' => date('Y-m-d')
  359. ],
  360. 'remark' => [
  361. 'value' => "\n他们之中离你最近的只有0.5km哦,来看看你附近的{$ta}吧~ ",
  362. ],
  363. ]
  364. ]
  365. ];
  366. $rand = rand(0, count($templates) - 1);
  367. $templateId = $templates[$rand]['template_id'];
  368. $parameters = $templates[$rand]['data'];
  369. $page = "pages/index/index";
  370. $weChatTemplate = new WeChatTemplateChannel();
  371. $weChatTemplate->setAppId(self::PUBLIC_ID)
  372. ->setTitle($title)
  373. ->toUser($user->openid)
  374. ->setPage($page)
  375. ->setTemplateId($templateId)
  376. ->setParameters($parameters)
  377. ->send();
  378. }
  379. return $users;
  380. }
  381. }