123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- /**
- * 推送宠物提醒脚本
- *
- * 从Redis队列中取出需要推送的提醒
- * Redis队列的Key为:`remind_list_` + 今天的日期时间戳
- *
- * 队列中的数据格式:
- * $item = [
- * 'remind_id' => '提醒ID',
- * 'user_id' => '用户ID',
- * 'pet_name' => '宠物名字',
- * 'remind_days' => '提前提醒的天数',
- * 'remind_type' => '提醒类型',
- * ];
- */
- class PushRemindCommand extends CConsoleCommand{
- public function run() {
- $redis_key = 'remind_list_' . strtotime('today');
- $redis = new Redis();
- $redis->connect(Yii::app()->redis->hostname, Yii::app()->redis->port);
- while (1) {
- $cache_data = $redis->brpop($redis_key, 5);
- if (isset($cache_data[1])) {
- $data = json_decode($cache_data[1], true);
- } else {
- continue;
- }
- if (!$data) {
- break;
- }
- // 文案
- $remind_types = self::$dog_remind_types;
- if (!$data['remind_days']) {
- $remind_copy = $data['pet_name'] . '今天要' . $remind_types[$data['remind_type']]['shorthand'] . '了哦';
- } else {
- $remind_copy = '距离' . $data['pet_name'] . '下一次' . $remind_types[$data['remind_type']]['shorthand'] . '天哦';
- }
- // 推送消息
- $z_action_cat = new ZActionCat();
- $news = $z_action_cat->getUnReadNews(new MongoId($data['user_id']));
- $push = Service::factory('PushService');
- $push_content = [
- 'title' => $remind_copy,
- 'content' => $remind_copy,
- 'news' => $news,
- 'type' => 'remind',
- 'data' => [],
- ];
- $template = $push->TransmissionTemplate([
- 'transmissionType' => 2, 'alert' => $remind_copy, 'transmissionContent' => $push_content, 'payload' => []
- ]);
- $push->pushMessageToSingle($template, $data['user_id']);
- }
- }
- public static $dog_remind_types = [
- // 第一针疫苗
- 'first_immunity' => [
- 'title' => '第一针疫苗',
- 'shorthand' => '免疫',
- 'desc' => [
- '出生后45天,注射第一针',
- ],
- 'project_type' => 1,
- 'remind_cycle' => '',
- ],
- // 第二针疫苗
- 'second_immunity' => [
- 'title' => '第二针疫苗',
- 'shorthand' => '免疫',
- 'desc' => [
- '与上一针间隔21天'
- ],
- 'project_type' => 1,
- 'remind_cycle' => '',
- ],
- // 第三针疫苗+狂犬疫苗
- 'third_immunity' => [
- 'title' => '第三针疫苗+狂犬疫苗',
- 'shorthand' => '免疫',
- 'desc' => [
- '与上一针间隔21天'
- ],
- 'project_type' => 1,
- 'remind_cycle' => '',
- ],
- // 补充疫苗+狂犬疫苗
- 'other_immunity' => [
- 'title' => '补充疫苗+狂犬疫苗',
- 'shorthand' => '免疫',
- 'desc' => [
- '每年注射一次',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 year',
- ],
- // 体内驱虫
- 'inside_deworming' => [
- 'title' => '体内驱虫',
- 'shorthand' => '体内驱虫',
- 'desc' => [
- '1月龄以下的狗狗,需资讯医生使用驱虫药;',
- '1月龄以上6月龄以下的狗狗,每隔一个月驱虫一次;',
- '6月龄以上的狗狗,每隔三个月驱虫一次',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '3 month',
- ],
- // 体外驱虫
- 'outside_deworming' => [
- 'title' => '体外驱虫',
- 'shorthand' => '体外驱虫',
- 'desc' => [
- '6周龄以下或者体重少于1公斤的狗狗,需咨询医生使用体外驱虫药;',
- '6周龄以上的狗狗,每隔一个月驱虫一次。',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 month',
- ],
- // 体检
- 'physical_examination' => [
- 'title' => '体检',
- 'shorthand' => '体检',
- 'desc' => [
- '宠物体检一般一年一次即可;',
- '应将宠物送到正规专业的动物医院进行体检。',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 year',
- ],
- // 洗澡
- 'shower' => [
- 'title' => '洗澡',
- 'shorthand' => '洗澡',
- 'desc' => [
- '冬天一般每15天一次,夏天一般每8天一次;',
- '在空气湿度大或阴雨天时,应延期洗澡为宜。',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '8 day',
- ],
- // 剪指甲
- 'shear_nails' => [
- 'title' => '剪指甲',
- 'shorthand' => '剪指甲',
- 'desc' => [
- '一般狗狗每隔7天修剪一次;',
- '根据指甲长度速度,可适当延后。'
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 week',
- ],
- // 剪毛
- 'shearing' => [
- 'title' => '剪毛',
- 'shorthand' => '剪毛',
- 'desc' => [
- '视狗狗毛发生长程度而定,一般一个月修剪一次即可;',
- '短毛狗可不需要剪毛或者相对减少剪毛次数。'
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 month',
- ],
- // 刷牙
- 'brush_teeth' => [
- 'title' => '刷牙',
- 'shorthand' => '刷牙',
- 'desc' => [
- '建议每7天至少帮狗狗刷一次牙;',
- '因为牙刷的毛质较硬,在帮狗狗刷牙的时候切记不能用力,以免牙龈出血。'
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 week',
- ],
- // 挤肛门腺
- 'anal_glands' => [
- 'title' => '挤肛门腺',
- 'shorthand' => '挤肛门腺',
- 'desc' => [
- '挤肛门腺次数不用太频繁,15天一次即可;',
- '定期检查肛门的液囊。',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '15 day',
- ],
- // 耳道清理
- 'ears_clean' => [
- 'title' => '耳道清理',
- 'shorthand' => '耳道清理',
- 'desc' => [
- '建议每7天帮狗狗清理一次耳道;',
- '拔除耳毛不可经常,间隔期十天至一个月。',
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 week',
- ],
- // 清洁眼睛
- 'eyes_clean' => [
- 'title' => '清洁眼睛',
- 'shorthand' => '清洁眼睛',
- 'desc' => [
- '建议7天至少帮狗狗清洁眼睛一次;',
- '建议减少使用含类固醇的眼药水,用久了会容易导致青光眼,必须谨慎。'
- ],
- 'project_type' => 2,
- 'remind_cycle' => '1 week',
- ],
- ];
- }
|