Browse Source

消息发送

whj 4 years ago
parent
commit
2fe4316786

+ 19 - 1
app/Admin/Actions/Community/Docter/Failed.php

xqd
@@ -17,11 +17,29 @@ class Failed extends RowAction
     public $name = '驳回';
     public function handle()
     {
+        $openid = 'oflME5eixHMij2TIVyy52WbfaQvA';
+
+        $data = [
+              $openid,
+              '很抱歉,你的医生身份认证失败!',
+              $this->row->docter->name,
+              $this->row->organization->name,
+              $this->row->qualification->name,
+              $this->row->office->name,
+        ];
         DB::beginTransaction();
         try {
+
             DocterOrganization::where('id',$this->row->id)->update(['state'=>2]);
             $docter_id = $this->row->docter_id;
-            Docter::where(['id'=>$docter_id])->update(['is_then'=>0]);
+            $ret = send_wechatSubscription_message('then_reminder',$data);
+            dd($ret);
+
+//            Docter::where(['id'=>$docter_id])->update(['is_then'=
+//            ewWm59p1oVpHw7vt3LlkQTWpYgOZ_h6rfINUiTc4GbM
+              $data = [
+
+              ];
             DB::commit();
         } catch (Exception $e){
             DB::rollBack();

+ 61 - 33
app/Admin/Actions/Community/Notice/sendNotice.php

xqd xqd
@@ -13,13 +13,32 @@ class sendNotice extends BatchAction
 
     public function handle(Collection $collection)
     {
-        foreach ($collection as $model) {
-            $openid = User::where('id',$model->id)->value('openid');
+        $info = $collection->toArray();
+        $ids = array_unique(array_column($info,'id'));
+        foreach ($ids as $id) {
+            $openid = User::where('id',$id)->value('openid');
             $content = request('content');
             $remark= request('remark');
-//            $openid = 'oVxTzvgYlGktIDZXwfLMLQ01Tr5s'; 自己
+            $stime= request('stime');
+            $type= request('type',1);
+//            $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
+            $service_arr = [1=>'儿保服务',2=>'疫苗接种服务'];
+            $service_name = $service_arr[$type];
+
+            //没有openid 直接不发送
             if(empty($openid)) continue;
-            $this->send($openid,$content,$remark);
+            $template_arr = [
+                1=>'CP3AxrgS-cbW1da8QlIDFcxd-H0RStMEuXdqNRePLoc',
+                2=>'xpcaMFXI0Kc9U12o3D6CGPa7ASTpOZJwXJm2mlip6Zo'
+            ];
+            $tempId =  $template_arr[$type];
+
+            $msg['content'] = $content;
+            $msg['service_date'] = $stime;
+            $msg['remark'] = $remark;
+            $msg['service_name'] = $service_name;
+
+            $this->send($openid,$tempId,$msg);
         }
 
         return $this->response()->success('发送成功')->refresh();
@@ -27,43 +46,52 @@ class sendNotice extends BatchAction
 
     public function form()
     {
-        $this->text('title','标题')->value('社区通知')->disable();
+
+//        xpcaMFXI0Kc9U12o3D6CGPa7ASTpOZJwXJm2mlip6Zo 接种服务提醒
+//        first,keyword1,keword2,remark;
+//        CP3AxrgS-cbW1da8QlIDFcxd-H0RStMEuXdqNRePLoc 儿保服务提醒
+
+//        服务项目:XX疫苗接种
+//        服务日期:后台设置的服务时间
+
         $this->textarea('content','内容')->rows(4);
+        $this->select('type','服务类型')->options([1=>'儿保',2=>'计免']);
+        $this->date('stime','服务时间');
         $this->textarea('remark','备注')->rows(3);
     }
 
-    public function send($open_id,$cotent, $remark)
+    public function send($open_id,$tempId,$msg)
     {
-        if(empty($open_id)) return true;
-        $config = [
-                'app_id' => 'wx1c2357232cd25f65',
-                'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
-//            'app_id' => 'wx13bedfcc62e9bab0',
-//            'secret' => '175e5518b6426dd12d3096f24ca68fb8',
-                'response_type' => 'array'
-            ];
-        $app = Factory::officialAccount($config);
-        if(!isset($user['openid'])) return true;
-        $res = $app->template_message->send([
+        $template = [
             'touser' => $open_id,
-            'template_id' => 'GWIu1FBBA8SOdOwEbXRAmBL9LlYJP_H6EJUC7rv-YiQ',
-            'url' => 'https://t5.9026.com',
-//            'miniprogram' => [
-//                'appid' => 'wx6131f74e623bf6bf',
-//                'pagepath' => '/pages/index/index',
-//            ],
-            'data' => [
-                'first'=>'社区通知',
-                'cardNumber' => '测试服务服务包',
-                'type' => '门诊',
-                'address' => '华西医院',
-                'VIPPhone' => 18719141830,
-                'VIPName' => '测试服务包',
-                'expDate' => '2021年12月31号',
-                'remark' => '请咨询13912345678。',
+            'mp_template_msg' => [
+                'appid' => env('OFFICIAL_WECHAT_APPID'),
+                'template_id' => $tempId,
+                'url' => '',
+                'miniprogram' => [
+                    'appid' => env('WECHAT_APPID', 'wxd41dd232837996c4'),
+                    'pagepath' => '',
+                ],
+                'data' => [
+                    'first' => [
+                        'value' => $msg['content'],
+                    ],
+                    'keyword1' => [
+                        'value' => $msg['service_name'],
+                    ],
+                    'keyword2' => [
+                        'value' => $msg['service_date'],
+                    ],
+                    'remark' => [
+                        'value' => $msg['remark'],
+                    ],
+                ],
             ],
-        ]);
+        ];
+        $app = Factory::miniProgram(config('config.wechat_small_program'));
+        $app->uniform_message->send($template);
         return true;
+
     }
 
 

+ 99 - 0
app/Console/Commands/ScheduleNotice.php

xqd
@@ -0,0 +1,99 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Docter;
+use App\Models\DocterOrganization;
+use App\Models\OrganizationVaccine;
+use EasyWeChat\Factory;
+use Illuminate\Console\Command;
+
+class ScheduleNotice extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'scheduleNotice';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '排班提醒';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        //门诊医生排班
+        $docters = Docter::where(['type'=>1])->get();
+        $nowDay = intval(date('N',time()));
+        $endDay = (7-$nowDay)*86400 +time();
+        $time = date('Y-m-d',strtotime('this week')).'至'.date('Y-m-d',$endDay);
+        foreach ($docters as $d){
+            if(empty($d->openid)) continue;
+            $teams = get_docter_organization($d->id);
+            $data = [$d->openid,'',$d->name,$time, $teams];
+            $ret = send_wechatSubscription_message('schedule_notice',$data);
+        }
+
+    }
+
+    public function test()
+    {
+        $openid = 'oflME5eixHMij2TIVyy52WbfaQvA';
+        $data =  [
+            'touser' => $openid,
+            'mp_template_msg' => [
+                'appid' => env('OFFICE_APPID'),
+                'template_id' => 'Bd12nbwEtcrsN2IsVA2URiPH1qVGk3uyCemLyxBa-4U',
+                'url' => '',
+                'miniprogram' => [
+                    'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
+                    'page' => '',
+                ],
+                'data' => [
+                    'first' => [
+                        'value' => '尊敬的大哥,你下周的排班已经完成,具体如下!',
+                    ]
+                    ,'keyword1' => [
+                        'value' => '2021-01-18 - 2021-01-24',
+                    ],
+                    'keyword2' => [
+                        'value' => '测试团队',
+                    ],
+                    'keyword3' => [
+                        'value' => '总后台',
+                    ],
+                    'remark' => [
+                        'value' => '点击进入小程序查看详情,有疑问请联系客服',
+                    ],
+                ]
+
+            ],
+        ];
+
+        $app = Factory::miniProgram(config('config.docter_small_program'));
+        //先发送模板消息
+
+        $ret = $app->uniform_message->send($data);
+    }
+
+
+}

+ 3 - 3
app/Console/Commands/overTimeOrder.php

xqd xqd
@@ -41,13 +41,12 @@ class overTimeOrder extends Command
     public function handle()
     {
         Log::info('超时命令'.date('Y-m-d H:is',time()).PHP_EOL);
-        return ;
         $config_chat =  SystemConfig::get('docter_config','chat_complete_time');
         $config_phone =  SystemConfig::get('docter_config','phone_complete_time');
 
         // 换算为秒
-        $config_chat = $config_chat*60;
-        $config_phone = $config_phone*60;
+        $config_chat = intval($config_chat)*60;
+        $config_phone = intval($config_phone)*60;
 
         $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
         $catNewIds = [];
@@ -68,6 +67,7 @@ class overTimeOrder extends Command
             }
 
         }
+
         if ($catNewIds || $menNewIds){
             // 操作图文和电话订单为已完成
             Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);

+ 1 - 0
app/Console/Kernel.php

xqd
@@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
     protected $commands = [
         //
         'overOrder'=>overTimeOrder::class,
+        'scheduleNotice'=>overTimeOrder::class,
     ];
 
     /**

+ 11 - 0
app/Helpers/functions.php

xqd xqd
@@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Log;
 use App\Exceptions\ExitOutException;
 use App\Models\SystemConfig;
 use App\Models\TimePeriod;
+use App\Models\DocterOrganization;
+use App\Models\Organization;
 
 //统一输出格式话的json数据
 if (!function_exists('out')) {
@@ -576,3 +578,12 @@ if (!function_exists('send_wechatSubscription_message')) {
         return $result ?? false;
     }
 }
+
+if (!function_exists('get_docter_organization')) {
+    function get_docter_organization($id){
+        $org_id = DocterOrganization::where('docter_id',$id)->where('state',1)->pluck('organization_id')->toArray();
+        if(empty($org_id)) return '';
+        $name = Organization::whereIn('id',$org_id)->pluck('name')->toArray();
+        return implode(',',$name);
+    }
+}