Swdz-WangHaiJun 4 years ago
parent
commit
d76f160cea

+ 79 - 2
app/Admin/Actions/Community/Notice/sendNotice.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Admin\Actions\Community\Notice;
 
 use App\User;
+use EasyWeChat\Factory;
 use Encore\Admin\Actions\BatchAction;
 use Illuminate\Database\Eloquent\Collection;
 
@@ -14,17 +15,93 @@ class sendNotice extends BatchAction
     {
         foreach ($collection as $model) {
             $openid = User::where('id',$model->id)->value('openid');
+            $content = request('content');
+            $remark= request('remark');
+            $openid = 'oVxTzvgYlGktIDZXwfLMLQ01Tr5s';
             if(empty($openid)) continue;
+            $this->send($openid,$content,$remark);
         }
 
-        return $this->response()->success('Success message...')->refresh();
+        return $this->response()->success('发送成功')->refresh();
     }
 
     public function form()
     {
-        $this->text('title','标题')->value('社区通')->disable();
+        $this->text('title','标题')->value('社区通')->disable();
         $this->textarea('content','内容')->value('社区通州')->rows(4);
         $this->textarea('remark','备注')->value('社区通州')->rows(3);
     }
 
+    public function send($open_id,$cotent, $remark)
+    {
+       if(empty($open_id)) return true;
+            $config = [
+                'app_id' => 'wx1c2357232cd25f65',
+                'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
+//                'app_id' => 'wx1c2357232cd25f65',
+//                'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
+//            'app_id' => 'wx13bedfcc62e9bab0',
+//            'secret' => '175e5518b6426dd12d3096f24ca68fb8',
+                'response_type' => 'array'
+            ];
+            $app = Factory::officialAccount($config);
+            $app->template_message->send([
+                'touser' => $open_id,
+                'template_id' => '3LUhWGlyiljxrT3Jh8orwQZ2LSHjfRs9SIHaB40O6q0',
+                'url' => 'http://47.94.228.245',
+                'miniprogram' => [
+                    'appid' => 'wx1c2357232cd25f65',
+                    'pagepath' => 'pages/index/index',
+                ],
+                'data' => [
+                    'first'=>'社区通知',
+                    'key1' => $cotent,
+                    'key2' => 18719141830,
+                    'key3' => '开发工程师',
+                    'key4' => '思维定制',
+                    'key5' => '2020-12-12',
+                ],
+            ]);
+    }
+
+
+    public function send2($user_ids,$number,$content){
+
+        if(!is_array($user_ids)) {
+            $user_ids = [$user_ids];
+        }
+
+
+        $app = app('wechat.official_account');
+
+        foreach($user_ids as $user_id) {
+
+            $user = (new User())->find($user_id);
+
+            if(empty($user) || empty($user['open_id'])) continue;
+
+            $official_open_id = $user->getOfficialOpenId($user['union_id']);
+
+            if(empty($official_open_id)) continue;
+
+            $result=$app->template_message->send([
+                'touser' => $official_open_id,
+                'template_id' => '4x80cGpV2boFdY7fm4QpsPBNo-FLytKjQGJKtZq_nr4',
+                'miniprogram' => [
+                    'appid' => env('WECHAT_MINI_PROGRAM_APPID'),
+                    'pagepath' => 'pages/index/index',
+                ],
+                'data' => [
+                    'first' => '作业许可状态改变',
+                    'keyword1' => $number,
+                    'keyword2' => $content,
+                    'keyword3' => $user->name,
+                    'remark' => '备注'
+                ],
+            ]);
+            var_dump($result);
+        }
+        return true;
+    }
+
 }

+ 120 - 0
app/Community/Controllers/UserNoticeController.php

xqd
@@ -0,0 +1,120 @@
+<?php
+
+namespace App\Community\Controllers;
+
+use App\Admin\Actions\Community\Notice\sendNotice;
+use App\models\Order;
+use Encore\Admin\Controllers\AdminController;
+use Encore\Admin\Facades\Admin;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Show;
+
+class UserNoticeController extends AdminController
+{
+    /**
+     * Title for current resource.
+     *
+     * @var string
+     */
+    protected $title = '群发通知';
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new Order());
+
+        $grid->model()->GroupBy('patient_id');
+        $user = Admin::user();
+        if(empty(request('product_type'))){
+            $user_ids = Order::whereIn('product_type',[4,5])->distinct()->pluck('user_id');
+            $grid->model()->whereIn('user_id',$user_ids)->distinct();
+        }
+
+        $grid->column('orderUser.nickname', __('用户'));
+        $grid->column('orderPatient.name', __('患者'));
+        $grid->column('orderPatient.relationship_type', __('关系'))->using([1=>'父亲',2=>'母亲',3=>'祖父',4=>'祖母',5=>'外祖父',6=>'外祖母',7=>'叔侄',8=>'其他']);
+        $grid->column('orderPatient.phone', __('用户手机号'));
+        $grid->column('orderPatient.birthday', __('出生日期'));
+
+        $grid->filter(function ($flter){
+            $flter->like('orderPatient.name','请输入用户姓名');
+            $flter->like('orderUser.nickname','请输入监护人姓名');
+            $flter->between('orderUser.birthday','生日')->datetime();
+            $flter->equal('product_type','用户类型')->select([4=>'计免',5=>'儿保']);
+        });
+
+        $grid->actions(function ($actions){
+            $actions->disableView();
+            $actions->disableDelete();
+            $actions->disableEdit();
+        });
+
+        $grid->batchActions(function ($batch) {
+            $batch->disableDelete();
+            $batch->add(new sendNotice());
+        });
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(Order::findOrFail($id));
+
+        $show->field('id', __('Id'));
+        $show->field('user_id', __('User id'));
+        $show->field('docter_id', __('Docter id'));
+        $show->field('patient_id', __('Patient id'));
+        $show->field('organization_id', __('Organization id'));
+        $show->field('order_sn', __('Order sn'));
+        $show->field('payment_type', __('Payment type'));
+        $show->field('product_type', __('Product type'));
+        $show->field('order_status', __('Order status'));
+        $show->field('payment_status', __('Payment status'));
+        $show->field('total_amount', __('Total amount'));
+        $show->field('payment_amount', __('Payment amount'));
+        $show->field('discount_amount', __('Discount amount'));
+        $show->field('payment_time', __('Payment time'));
+        $show->field('created_at', __('Created at'));
+        $show->field('updated_at', __('Updated at'));
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new Order());
+
+        $form->number('user_id', __('User id'));
+        $form->number('docter_id', __('Docter id'));
+        $form->number('patient_id', __('Patient id'));
+        $form->number('organization_id', __('Organization id'));
+        $form->text('order_sn', __('Order sn'));
+        $form->switch('payment_type', __('Payment type'))->default(1);
+        $form->switch('product_type', __('Product type'))->default(1);
+        $form->switch('order_status', __('Order status'))->default(1);
+        $form->switch('payment_status', __('Payment status'))->default(1);
+        $form->number('total_amount', __('Total amount'));
+        $form->number('payment_amount', __('Payment amount'));
+        $form->number('discount_amount', __('Discount amount'));
+        $form->number('payment_time', __('Payment time'));
+
+        return $form;
+    }
+}

+ 4 - 0
app/Community/routes.php

xqd
@@ -16,6 +16,10 @@ Route::resource('cdms_roles', PermissionController::class);
 Route::resource('docter_account', DocterAccountController::class);
 Route::resource('docter_chats', DocterChatController::class);
 Route::resource('notices', NoticeController::class);
+
+//群发通知
+Route::resource('user_notices', UserNoticeController::class);
+
 Route::get('send_notices', 'NoticeController@send');
 Route::resource('/docter_chats', DocterChatController::class);
 Route::get('/chats', 'DocterChatController@chats');