Ver Fonte

公众号消息通知

李浩杰 há 4 anos atrás
pai
commit
5b6093591f

+ 2 - 0
app/Http/Controllers/Admin/ProjectController.php

xqd xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
 
 use App\Models\AdminRoleModel;
 use App\Models\Department;
+use App\Models\Notification;
 use App\Models\Project;
 use App\Models\Road;
 use App\Models\Role;
@@ -128,6 +129,7 @@ class ProjectController extends BaseController
     public function change(Request $request)
     {
         $this->model->where('id', $request->input('id'))->update(['active' => $request->input('active')]);
+        Notification::sendProjectInfo($request->input('id'));
         return response()->json(['status' => 'success', 'info' => '操作成功']);
     }
 

+ 2 - 0
app/Http/Controllers/Api/mini/ProjectController.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Api\mini;
 
+use App\Models\Notification;
 use App\Models\Project;
 use App\Models\ProjectUser;
 use App\Models\User;
@@ -31,6 +32,7 @@ class ProjectController extends BaseController
             'user_id' => $request->input('user_id'),
             'project_role_id' => $request->input('project_role_id')
         ]);
+        Notification::sendAddUserInfo($res);
         if(!$res) return $this->error('添加失败');
         return $this->success('操作成功');
     }

+ 68 - 0
app/Models/Notification.php

xqd
@@ -154,6 +154,74 @@ class Notification extends BaseModel
         }
     }
 
+    /**
+     * 申请进度通知
+     * @param $project_id
+     */
+    public static function sendProjectInfo($project_id)
+    {
+        $project = Project::find($project_id);
+        if($project && isset($project['user_id'])) {
+            $user = User::find($project['user_id']);
+            if($user) {
+                $official_app = app('wechat.official_account.default');
+                $title = $project->active == 1 ? '您申请的项目已经通过审批,请及时查看!' : '您申请的项目未通过申请,请重新提交!';
+                $official_app->template_message->send([
+                    'touser' => $user['official_open_id'],
+                    'template_id' => 'NusdON_pl0l32P6rFeYOlvE-53QYvu_eRnn5LthaVdM',
+                    'miniprogram' => [
+                        'appid' => env('WECHAT_MINI_PROGRAM_APPID'),
+                        'pagepath' => 'pages/index/index',
+                    ],
+                    'data' => [
+                        'first' => $title,
+                        'keyword1' => $project->name,
+                        'keyword2' => $user->name,
+                        'keyword3' => '中铁二局',
+                        'keyword4' => '',
+                        'keyword5' => $project->created_at,
+                        'remark' => '点击进入小程序查看详情',
+                    ],
+                ]);
+            }
+        }
+    }
+
+    /**
+     * @param $project_user
+     * @return boolean
+     */
+    public static function sendAddUserInfo($project_user)
+    {
+        if(!$project_user) return false;
+        $project = Project::find($project_user->project_id);
+        if($project && isset($project['user_id'])) {
+            $user = User::find($project['user_id']);
+            $role = ProjectRole::find($project_user['project_role_id']);
+            $work_point = WorkPoint::find($project['work_point_id']);
+            if($user) {
+                $official_app = app('wechat.official_account.default');
+                $title = '你的项目授权审批已通过!';
+                $remark = '授权角色:' . $project->name . ' - ' . ($work_point ? $work_point->name : '') . ' - ' . ($role ? $role->name : '');
+                $official_app->template_message->send([
+                    'touser' => $user['official_open_id'],
+                    'template_id' => 'zzNETW2GEZ4_GfVp020yH8n9VL97G9EttONAtcrxG9c',
+                    'miniprogram' => [
+                        'appid' => env('WECHAT_MINI_PROGRAM_APPID'),
+                        'pagepath' => 'pages/index/index',
+                    ],
+                    'data' => [
+                        'first' => $title,
+                        'keyword1' => $user->name,
+                        'keyword2' => $project_user->created_at,
+                        'remark' => $remark,
+                    ],
+                ]);
+            }
+        }
+        return true;
+    }
+
     public function getNameContent()
     {
         $order = Order::find($this['order_id']);