PushRemindCommand.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /**
  3. * 推送宠物提醒脚本
  4. *
  5. * 从Redis队列中取出需要推送的提醒
  6. * Redis队列的Key为:`remind_list_` + 今天的日期时间戳
  7. *
  8. * 队列中的数据格式:
  9. * $item = [
  10. * 'remind_id' => '提醒ID',
  11. * 'user_id' => '用户ID',
  12. * 'pet_name' => '宠物名字',
  13. * 'remind_days' => '提前提醒的天数',
  14. * 'remind_type' => '提醒类型',
  15. * ];
  16. */
  17. class PushRemindCommand extends CConsoleCommand{
  18. public function run() {
  19. $redis_key = 'remind_list_' . strtotime('today');
  20. $redis = new Redis();
  21. $redis->connect(Yii::app()->redis->hostname, Yii::app()->redis->port);
  22. while (1) {
  23. $cache_data = $redis->brpop($redis_key, 5);
  24. if (isset($cache_data[1])) {
  25. $data = json_decode($cache_data[1], true);
  26. } else {
  27. continue;
  28. }
  29. if (!$data) {
  30. break;
  31. }
  32. // 文案
  33. $remind_types = self::$dog_remind_types;
  34. if (!$data['remind_days']) {
  35. $remind_copy = $data['pet_name'] . '今天要' . $remind_types[$data['remind_type']]['shorthand'] . '了哦';
  36. } else {
  37. $remind_copy = '距离' . $data['pet_name'] . '下一次' . $remind_types[$data['remind_type']]['shorthand'] . '天哦';
  38. }
  39. // 推送消息
  40. $z_action_cat = new ZActionCat();
  41. $news = $z_action_cat->getUnReadNews(new MongoId($data['user_id']));
  42. $push = Service::factory('PushService');
  43. $push_content = [
  44. 'title' => $remind_copy,
  45. 'content' => $remind_copy,
  46. 'news' => $news,
  47. 'type' => 'remind',
  48. 'data' => [],
  49. ];
  50. $template = $push->TransmissionTemplate([
  51. 'transmissionType' => 2, 'alert' => $remind_copy, 'transmissionContent' => $push_content, 'payload' => []
  52. ]);
  53. $push->pushMessageToSingle($template, $data['user_id']);
  54. }
  55. }
  56. public static $dog_remind_types = [
  57. // 第一针疫苗
  58. 'first_immunity' => [
  59. 'title' => '第一针疫苗',
  60. 'shorthand' => '免疫',
  61. 'desc' => [
  62. '出生后45天,注射第一针',
  63. ],
  64. 'project_type' => 1,
  65. 'remind_cycle' => '',
  66. ],
  67. // 第二针疫苗
  68. 'second_immunity' => [
  69. 'title' => '第二针疫苗',
  70. 'shorthand' => '免疫',
  71. 'desc' => [
  72. '与上一针间隔21天'
  73. ],
  74. 'project_type' => 1,
  75. 'remind_cycle' => '',
  76. ],
  77. // 第三针疫苗+狂犬疫苗
  78. 'third_immunity' => [
  79. 'title' => '第三针疫苗+狂犬疫苗',
  80. 'shorthand' => '免疫',
  81. 'desc' => [
  82. '与上一针间隔21天'
  83. ],
  84. 'project_type' => 1,
  85. 'remind_cycle' => '',
  86. ],
  87. // 补充疫苗+狂犬疫苗
  88. 'other_immunity' => [
  89. 'title' => '补充疫苗+狂犬疫苗',
  90. 'shorthand' => '免疫',
  91. 'desc' => [
  92. '每年注射一次',
  93. ],
  94. 'project_type' => 2,
  95. 'remind_cycle' => '1 year',
  96. ],
  97. // 体内驱虫
  98. 'inside_deworming' => [
  99. 'title' => '体内驱虫',
  100. 'shorthand' => '体内驱虫',
  101. 'desc' => [
  102. '1月龄以下的狗狗,需资讯医生使用驱虫药;',
  103. '1月龄以上6月龄以下的狗狗,每隔一个月驱虫一次;',
  104. '6月龄以上的狗狗,每隔三个月驱虫一次',
  105. ],
  106. 'project_type' => 2,
  107. 'remind_cycle' => '3 month',
  108. ],
  109. // 体外驱虫
  110. 'outside_deworming' => [
  111. 'title' => '体外驱虫',
  112. 'shorthand' => '体外驱虫',
  113. 'desc' => [
  114. '6周龄以下或者体重少于1公斤的狗狗,需咨询医生使用体外驱虫药;',
  115. '6周龄以上的狗狗,每隔一个月驱虫一次。',
  116. ],
  117. 'project_type' => 2,
  118. 'remind_cycle' => '1 month',
  119. ],
  120. // 体检
  121. 'physical_examination' => [
  122. 'title' => '体检',
  123. 'shorthand' => '体检',
  124. 'desc' => [
  125. '宠物体检一般一年一次即可;',
  126. '应将宠物送到正规专业的动物医院进行体检。',
  127. ],
  128. 'project_type' => 2,
  129. 'remind_cycle' => '1 year',
  130. ],
  131. // 洗澡
  132. 'shower' => [
  133. 'title' => '洗澡',
  134. 'shorthand' => '洗澡',
  135. 'desc' => [
  136. '冬天一般每15天一次,夏天一般每8天一次;',
  137. '在空气湿度大或阴雨天时,应延期洗澡为宜。',
  138. ],
  139. 'project_type' => 2,
  140. 'remind_cycle' => '8 day',
  141. ],
  142. // 剪指甲
  143. 'shear_nails' => [
  144. 'title' => '剪指甲',
  145. 'shorthand' => '剪指甲',
  146. 'desc' => [
  147. '一般狗狗每隔7天修剪一次;',
  148. '根据指甲长度速度,可适当延后。'
  149. ],
  150. 'project_type' => 2,
  151. 'remind_cycle' => '1 week',
  152. ],
  153. // 剪毛
  154. 'shearing' => [
  155. 'title' => '剪毛',
  156. 'shorthand' => '剪毛',
  157. 'desc' => [
  158. '视狗狗毛发生长程度而定,一般一个月修剪一次即可;',
  159. '短毛狗可不需要剪毛或者相对减少剪毛次数。'
  160. ],
  161. 'project_type' => 2,
  162. 'remind_cycle' => '1 month',
  163. ],
  164. // 刷牙
  165. 'brush_teeth' => [
  166. 'title' => '刷牙',
  167. 'shorthand' => '刷牙',
  168. 'desc' => [
  169. '建议每7天至少帮狗狗刷一次牙;',
  170. '因为牙刷的毛质较硬,在帮狗狗刷牙的时候切记不能用力,以免牙龈出血。'
  171. ],
  172. 'project_type' => 2,
  173. 'remind_cycle' => '1 week',
  174. ],
  175. // 挤肛门腺
  176. 'anal_glands' => [
  177. 'title' => '挤肛门腺',
  178. 'shorthand' => '挤肛门腺',
  179. 'desc' => [
  180. '挤肛门腺次数不用太频繁,15天一次即可;',
  181. '定期检查肛门的液囊。',
  182. ],
  183. 'project_type' => 2,
  184. 'remind_cycle' => '15 day',
  185. ],
  186. // 耳道清理
  187. 'ears_clean' => [
  188. 'title' => '耳道清理',
  189. 'shorthand' => '耳道清理',
  190. 'desc' => [
  191. '建议每7天帮狗狗清理一次耳道;',
  192. '拔除耳毛不可经常,间隔期十天至一个月。',
  193. ],
  194. 'project_type' => 2,
  195. 'remind_cycle' => '1 week',
  196. ],
  197. // 清洁眼睛
  198. 'eyes_clean' => [
  199. 'title' => '清洁眼睛',
  200. 'shorthand' => '清洁眼睛',
  201. 'desc' => [
  202. '建议7天至少帮狗狗清洁眼睛一次;',
  203. '建议减少使用含类固醇的眼药水,用久了会容易导致青光眼,必须谨慎。'
  204. ],
  205. 'project_type' => 2,
  206. 'remind_cycle' => '1 week',
  207. ],
  208. ];
  209. }