Ver código fonte

消息管理

李浩杰 4 anos atrás
pai
commit
a6ce7c0eea

+ 30 - 26
app/Http/Controllers/Admin/TestController.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Admin;
 
+use App\Models\Notification;
 use App\Models\Project;
 use App\Models\User;
 use App\Models\UserAuth;
@@ -13,31 +14,34 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        $user = User::where('phone', '13438082119')->first();
-        User::where('phone', 'like', '%1343808211%')->update([
-            'open_id' => $user->open_id,
-            'union_id' => $user->union_id,
-            'official_open_id' => $user->official_open_id
-        ]);
-        dd(User::where('phone', 'like', '%1343808211%')->pluck('union_id'));
-        $app = app('wechat.official_account.default');
-        $res = $app->template_message->send([
-            'touser' => 'oEDlJ5p8EFuHepjBi0cASmHjb7Qg',
-            'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
-            'miniprogram' => [
-                'appid' => 'xxxxxxx',
-                'pagepath' => 'pages/xxx',
-            ],
-            'data' => [
-                'first' => '您有一条待审核的订单,请注意查看!',
-                'keyword1' => '2010-01-01',
-                'keyword2' => '设备租赁订单',
-                'keyword3' => '待审核/机电负责人',
-                'keyword4' => 'XX-项目',
-                'keyword5' => 'XXXXXX',
-                'remark' => '点击进入小程序查看详情,请及时处理。',
-            ],
-        ]);
-        dd($res);
+        $info = Notification::orderBy('id', 'desc')->first();
+        dd($info->sendOfficialInfo());
+        return false;
+//        $user = User::where('phone', '13438082119')->first();
+//        User::where('phone', 'like', '%1343808211%')->update([
+//            'open_id' => $user->open_id,
+//            'union_id' => $user->union_id,
+//            'official_open_id' => $user->official_open_id
+//        ]);
+//        dd(User::where('phone', 'like', '%1343808211%')->pluck('union_id'));
+//        $app = app('wechat.official_account.default');
+//        $res = $app->template_message->send([
+//            'touser' => 'oEDlJ5p8EFuHepjBi0cASmHjb7Qg',
+//            'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+//            'miniprogram' => [
+//                'appid' => 'xxxxxxx',
+//                'pagepath' => 'pages/xxx',
+//            ],
+//            'data' => [
+//                'first' => '您有一条待审核的订单,请注意查看!',
+//                'keyword1' => '2010-01-01',
+//                'keyword2' => '设备租赁订单',
+//                'keyword3' => '待审核/机电负责人',
+//                'keyword4' => 'XX-项目',
+//                'keyword5' => 'XXXXXX',
+//                'remark' => '点击进入小程序查看详情,请及时处理。',
+//            ],
+//        ]);
+//        dd($res);
     }
 }

+ 17 - 11
app/Models/Notification.php

xqd
@@ -130,20 +130,26 @@ class Notification extends BaseModel
     public static function createAndSend($data)
     {
         $item = Notification::create($data);
-        $content = $item->getNameContent();
-        $user = User::find($data['user_id']);
+        $item->sendOfficialInfo();
+    }
+
+    public function sendOfficialInfo()
+    {
+        $content = $this->getNameContent();
+        $user = User::find($this['user_id']);
         $official_app = app('wechat.official_account.default');
         if($content && isset($content['official']) && $user && $user['official_open_id']) {
             $info = $content['official'];
-            $official_app->template_message->send([
-                'touser' => $user['official_open_id'],
-                'template_id' => $info['template_id'],
-                'miniprogram' => [
-                    'appid' => env('WECHAT_MINI_PROGRAM_APPID'),
-                    'pagepath' => $info['page'],
-                ],
-                'data' => $info['data'],
-            ]);
+            dd($info['data']);
+//            $official_app->template_message->send([
+//                'touser' => $user['official_open_id'],
+//                'template_id' => $info['template_id'],
+//                'miniprogram' => [
+//                    'appid' => env('WECHAT_MINI_PROGRAM_APPID'),
+//                    'pagepath' => $info['page'],
+//                ],
+//                'data' => $info['data'],
+//            ]);
         }
     }