Ver código fonte

Merge remote-tracking branch 'origin/test' into test

liuzejian 1 ano atrás
pai
commit
1e117a00de

+ 10 - 10
modules/Channel/Http/Controllers/WechatOpenPlatformController.php

@@ -130,13 +130,13 @@ class WechatOpenPlatformController extends CatchController
 
 
         $server = $openPlatform->server;
         $server = $openPlatform->server;
         $message = $server->getMessage();
         $message = $server->getMessage();
-        // myLog("wx-xiaoxi")->info('-------开始处理---'.get_date());
-        // myLog("wx-xiaoxi")->info([
-        //     'authorizer_appid' => $authorizer_appid,
-        //     'component_appid' => $component_appid,
-        //     'param' => $request->all(),
-        //     'msg' => $message,
-        // ]);
+        myLog("wx-xiaoxi")->info('-------开始处理---'.get_date());
+        myLog("wx-xiaoxi")->info([
+            'authorizer_appid' => $authorizer_appid,
+            'component_appid' => $component_appid,
+            'param' => $request->all(),
+            'msg' => $message,
+        ]);
         $appInfo = WechatOpenPlatformService::getRefreshToken($authorizer_appid,$component_appid);
         $appInfo = WechatOpenPlatformService::getRefreshToken($authorizer_appid,$component_appid);
         $wechatAppId = getProp($appInfo,'id');
         $wechatAppId = getProp($appInfo,'id');
 
 
@@ -144,9 +144,9 @@ class WechatOpenPlatformController extends CatchController
         unset($appInfo);
         unset($appInfo);
 
 
         $app->server->push(function ($message) use($app,$authorizer_appid,$wechatAppId) {
         $app->server->push(function ($message) use($app,$authorizer_appid,$wechatAppId) {
-            // myLog("wx-xiaoxi")->info("----文本消息---");
-            // myLog("wx-xiaoxi")->info("体消息:");
-            // myLog("wx-xiaoxi")->info($message);
+            myLog("wx-xiaoxi")->info("----文本消息---");
+            myLog("wx-xiaoxi")->info("体消息:");
+            myLog("wx-xiaoxi")->info($message);
             return WechatCommonService::handleMessage($app,$wechatAppId ,$authorizer_appid,$message);
             return WechatCommonService::handleMessage($app,$wechatAppId ,$authorizer_appid,$message);
         });
         });
         // myLog("wx-xiaoxi")->info('-------结束处理---'.get_date());
         // myLog("wx-xiaoxi")->info('-------结束处理---'.get_date());

+ 76 - 54
modules/WechatPlatform/Http/Controllers/WechatMenuController.php

@@ -22,6 +22,7 @@ use Modules\WechatPlatform\Services\WechatMenuService;
 class WechatMenuController extends CatchController
 class WechatMenuController extends CatchController
 {
 {
     use UserTrait;
     use UserTrait;
+
     /**
     /**
      *  关键词列表
      *  关键词列表
      * name: List
      * name: List
@@ -40,8 +41,9 @@ class WechatMenuController extends CatchController
 
 
     public function add(WechatMenuRequest $request)
     public function add(WechatMenuRequest $request)
     {
     {
-
-        $param  = $this->handleParam($request->validated());
+        $param = $request->validated();
+        $param['msg_content'] = $request->input('msg_content');
+        $param = $this->handleParam($param);
         $userContext = $this->getUserContext(null);
         $userContext = $this->getUserContext(null);
         $param['user_id'] = $userContext['loginUser']->id;
         $param['user_id'] = $userContext['loginUser']->id;
         $param['puser_id'] = $userContext['loginUser']->pid;
         $param['puser_id'] = $userContext['loginUser']->pid;
@@ -49,17 +51,21 @@ class WechatMenuController extends CatchController
         return WechatMenuService::addMenu($param);
         return WechatMenuService::addMenu($param);
     }
     }
 
 
-    public function edit($id,WechatMenuRequest $request)
+    public function edit($id, WechatMenuRequest $request)
     {
     {
-        $param  = $this->handleParam($request->validated());
-        return WechatMenuService::updateMenu($id,$param);
+        $param = $request->validated();
+        $param['msg_content'] = $request->input('msg_content');
+        $param = $this->handleParam($param);
+        return WechatMenuService::updateMenu($id, $param);
     }
     }
 
 
-    public function detail($id){
+    public function detail($id)
+    {
         return WechatMenuService::detail($id);
         return WechatMenuService::detail($id);
     }
     }
 
 
-    public function authList($id){
+    public function authList($id)
+    {
         $userId = $this->getLoginUserId();
         $userId = $this->getLoginUserId();
         return WechatMenuService::authList($id, $userId);
         return WechatMenuService::authList($id, $userId);
     }
     }
@@ -81,7 +87,7 @@ class WechatMenuController extends CatchController
      * @param $id
      * @param $id
      * date 2023/07/12 07:18
      * date 2023/07/12 07:18
      */
      */
-    public function  allocation($id,Request $request)
+    public function allocation($id, Request $request)
     {
     {
         if (!$request->has('wx_auth_ids')) {
         if (!$request->has('wx_auth_ids')) {
             WechatMenuService::throwErrMsg("参数错误");
             WechatMenuService::throwErrMsg("参数错误");
@@ -91,9 +97,10 @@ class WechatMenuController extends CatchController
         } else {
         } else {
             $wxAuthIds = [];
             $wxAuthIds = [];
         }
         }
-        return WechatMenuService::allocation($id,$wxAuthIds);
+        return WechatMenuService::allocation($id, $wxAuthIds);
     }
     }
-        // 处理参数
+
+    // 处理参数
     private function handleParam($param)
     private function handleParam($param)
     {
     {
         $info = DB::table('miniprogram')->where('id', $param['miniprogram_id'])->first();
         $info = DB::table('miniprogram')->where('id', $param['miniprogram_id'])->first();
@@ -111,70 +118,85 @@ class WechatMenuController extends CatchController
         if (empty($info)) {
         if (empty($info)) {
             WechatMenuService::throwErrMsg("没有此小程序的使用权限");
             WechatMenuService::throwErrMsg("没有此小程序的使用权限");
         }
         }
-        if (count($param['content']) >3){
+        if (count($param['content']) > 3) {
             WechatMenuService::throwErrMsg("底部菜单不能超过3个");
             WechatMenuService::throwErrMsg("底部菜单不能超过3个");
         }
         }
-        $clicks = [];
-        foreach ($param['content'] as  $val){
-            if (!empty(getProp($val,'sub_button'))){
-                foreach ($val['sub_button'] as $sub){
-                    if (getProp($sub,'type') == 'miniprogram'){
+        // $clicks = [];
+        $msgContent = [];
+        foreach ($param['content'] as &$val) {
+            if (!empty(getProp($val, 'sub_button'))) {
+                foreach ($val['sub_button'] as &$sub) {
+                    if (getProp($sub, 'type') == 'miniprogram') {
                         $sub['appid'] = $param['miniprogram_appid'];
                         $sub['appid'] = $param['miniprogram_appid'];
                         $sub['pagepath'] = $sub['url'];
                         $sub['pagepath'] = $sub['url'];
                     }
                     }
-                    if (getProp($sub,'type') == 'click'){
-                        $clicks[] = $sub['key'];
+                    if (getProp($sub, 'type') == 'click') {
+                        // $clicks[] = $sub['key'];
+                        $msgContent[] = [$sub['key'] => $sub['content']];
+                    }
+                    if (!in_array(getProp($sub, 'type'), ['view', 'miniprogram'])) {
+                        unset($sub['url']);
                     }
                     }
                 }
                 }
-            }else{
-                if (getProp($val,'type') == 'miniprogram'){
+            } else {
+                if (getProp($val, 'type') == 'miniprogram') {
                     $val['appid'] = $param['miniprogram_appid'];
                     $val['appid'] = $param['miniprogram_appid'];
                     $val['pagepath'] = $val['url'];
                     $val['pagepath'] = $val['url'];
                 }
                 }
-                if (getProp($val,'type') == 'click'){
-                    $clicks[] = $val['key'];
-                }
-            }
-        }
-        unset($val,$sub,$info);
-        $param['msg_content']= [];
-        // 有点击事件
-        if (!empty($clicks)){
-            $msgContent = [];
-            $msg = getProp($param,'msg_content');
-            if (empty($msg) || !is_array($msg)){
-                WechatMenuService::throwErrMsg("发送的文本信息不能为空");
-            }
-            foreach ($clicks as $val){
-                $temp = getProp($msg,$val);
-                if (empty($temp) || !is_array($temp)){
-                    WechatMenuService::throwErrMsg("发送的文本信息格式不正确");
+                if (getProp($val, 'type') == 'click') {
+                    // $clicks[] = $val['key'];
+                    $msgContent[] = [$val['key'] => $val['content']];
                 }
                 }
-                $contents = "";
-                foreach ($temp as  & $item){
-                    if (getProp($item,'url')){
-                        $item['content'] = "<a href=\"\" data-miniprogram-appid=\"{$param['miniprogram_appid']}\" data-miniprogram-path=\"{$val['url']}\">{$val['title']}</a>";
-                    }else{
-                        $item['content'] = $item['tittle'];
-                    }
-                    $contents .=  $item['content']."\n";
+                if (getProp($val, 'type') == 'view') {
+                    unset($val['url']);
                 }
                 }
-                rtrim($contents, "\n");
-                $temp['content'] = $contents;
-                $msgContent = [$val => $temp];
+
             }
             }
-            $param['msg_content'] = $msgContent;
-            unset($msgContent);
-            unset($temp,$val,$item);
+
         }
         }
+        $param['msg_content'] = $msgContent;
+        // unset($val,$sub,$info);
+        // // 有点击事件
+        // if (!empty($clicks)){
+        //     $msgContent = [];
+        //     $msg = getProp($param,'msg_content');
+        //     if (empty($msg) || !is_array($msg)){
+        //         WechatMenuService::throwErrMsg("发送的文本信息不能为空");
+        //     }
+        //     foreach ($clicks as $val){
+        //         $temp = getProp($msg,$val);
+        //         if (empty($temp) || !is_array($temp)){
+        //             WechatMenuService::throwErrMsg("发送的文本信息格式不正确");
+        //         }
+        //         $contents = "";
+        //         foreach ($temp as  & $item){
+        //             if (getProp($item,'url')){
+        //                 $item['content'] = "<a href=\"\" data-miniprogram-appid=\"{$param['miniprogram_appid']}\" data-miniprogram-path=\"{$item['url']}\">{$item['title']}</a>";
+        //             }else{
+        //                 $item['content'] = $item['title'];
+        //             }
+        //             $contents =  $contents.$item['content']."\n";
+        //         }
+        //
+        //         rtrim($contents, "\n");
+        //         $temp['content'] = $contents;
+        //         $msgContent = [$val => $temp];
+        //     }
+        //     $param['msg_content'] = $msgContent;
+        //     unset($msgContent);
+        //     unset($temp,$val,$item);
+        // }else{
+        //     $param['msg_content']= [];
+        // }
         return $param;
         return $param;
     }
     }
 
 
-    public function test(){
+    public function test()
+    {
         $info = WechatOpenPlatformService::getAppInfoById(8);
         $info = WechatOpenPlatformService::getAppInfoById(8);
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($info->component_appid);
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($info->component_appid);
         $openPlatform = WechatOpenPlatformService::buildApplication($componentInfo);
         $openPlatform = WechatOpenPlatformService::buildApplication($componentInfo);
-        $app = $openPlatform->officialAccount($info->authorizer_appid, getProp($info,'authorizer_refresh_token'));
+        $app = $openPlatform->officialAccount($info->authorizer_appid, getProp($info, 'authorizer_refresh_token'));
         unset($appInfo);
         unset($appInfo);
         return $app->menu->list();
         return $app->menu->list();
     }
     }

+ 1 - 1
modules/WechatPlatform/Models/WechatAccountMenuDetail.php

@@ -10,7 +10,7 @@ class WechatAccountMenuDetail extends BaseModel
     protected $table = 'wechat_account_menu_detail';
     protected $table = 'wechat_account_menu_detail';
 
 
     protected $fillable = [
     protected $fillable = [
-        'id', 'user_id', 'puser_id','type', 'menu_id','msg_content', 'appid', 'wechat_authorization_info_id', 'miniprogram_id', 'nick_name', 'content', 'status', 'updated_at', 'created_at',
+        'id', 'user_id', 'puser_id','wx_menuid','type', 'menu_id','msg_content', 'appid', 'wechat_authorization_info_id', 'miniprogram_id', 'nick_name', 'content', 'status', 'updated_at', 'created_at',
     ];
     ];
     protected $casts = ['content' => 'array','msg_content' => 'array'];
     protected $casts = ['content' => 'array','msg_content' => 'array'];
 }
 }

+ 1 - 1
modules/WechatPlatform/Services/WechatKeywordsService.php

@@ -285,7 +285,7 @@ class WechatKeywordsService extends BaseService
             return "";
             return "";
         }
         }
         $set = self::getConfig($info->user_id,$info->puser_id,$info->miniprogram_id);
         $set = self::getConfig($info->user_id,$info->puser_id,$info->miniprogram_id);
-        if (getProp($set['data'] == 0)){
+        if (getProp($set,'data') == 0){
             return  '';
             return  '';
         }
         }
         WechatAccountKeywordLog::where('id', $info->id)->increment('send_total', 1);
         WechatAccountKeywordLog::where('id', $info->id)->increment('send_total', 1);

+ 106 - 40
modules/WechatPlatform/Services/WechatMenuService.php

@@ -10,6 +10,7 @@
 namespace Modules\WechatPlatform\Services;
 namespace Modules\WechatPlatform\Services;
 
 
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
+use Modules\Channel\Services\WechatOpenPlatform\WechatOpenPlatformService;
 use Modules\Common\Services\BaseService;
 use Modules\Common\Services\BaseService;
 use Modules\WechatPlatform\Models\WechatAccountMenuDetail;
 use Modules\WechatPlatform\Models\WechatAccountMenuDetail;
 use Modules\WechatPlatform\Models\WechatMenu;
 use Modules\WechatPlatform\Models\WechatMenu;
@@ -48,38 +49,73 @@ class WechatMenuService extends BaseService
         if (is_empty($info)) {
         if (is_empty($info)) {
             self::throwErrMsg('该菜单不存在或已删除');
             self::throwErrMsg('该菜单不存在或已删除');
         }
         }
-        $appIds = WechatAccountMenuDetail::where(['status' => 1, 'meun_id' => $info->id])->pluck('id')->toArray();
-        WechatMenu::query()->where('id', $id)->update($param);
+        $appIds = WechatAccountMenuDetail::where(['status' => 1, 'menu_id' => $info->id])->pluck('id')->toArray();
+        WechatMenu::where('id', $id)->update($param);
         $data = [
         $data = [
             'type' => $param['type'],
             'type' => $param['type'],
             'content' => $param['content'],
             'content' => $param['content'],
             'msg_content' => $param['msg_content']
             'msg_content' => $param['msg_content']
         ];
         ];
-        WechatAccountMenuDetail::where('meun_id', $id)->update($data);
+        WechatAccountMenuDetail::where('menu_id', $id)->update($data);
         // 更新公众号菜单
         // 更新公众号菜单
-        self::createWechatMenus($appIds);
+        self::createWechatMenus($appIds,$id);
         return ['msg' => '操作成功'];
         return ['msg' => '操作成功'];
     }
     }
 
 
     /**
     /**
-     *  创建微信菜单
+     * 创建微信菜单
      * name: createWechatMenus
      * name: createWechatMenus
      * @param array $appIds
      * @param array $appIds
+     * @param $menuId
      * @return bool
      * @return bool
-     * date 2023/07/12 07:16
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     * date 2023/07/12 14:29
      */
      */
-    private static function createWechatMenus(array $appIds)
+    private static function createWechatMenus(array $appIds,$menuId)
     {
     {
         if (empty($appIds)) {
         if (empty($appIds)) {
             return true;
             return true;
         }
         }
-        $info = WechatAccountMenuDetail::query()->whereIn('id', $appIds)->get();
+        $info = WechatAccountMenuDetail::query()->whereIn('wechat_authorization_info_id', $appIds)->where('menu_id',$menuId)->get();
         foreach ($info as $val) {
         foreach ($info as $val) {
+            $app = self::getofficialAccount($val->wechat_authorization_info_id);
+            if ($val->wx_menuid) {
+                // 有菜单则删除菜单
+                $app->menu->delete($val->wx_menuid);
+            }
+            $matchRule = [
+                "client_platform_type" => $val->type == "iso" ? "1" : "2",
+            ];
+            $res = $app->menu->create($val->content, $matchRule);
+            myLog('wx-meun')->info(['res' => $res]);
 
 
+            $errcode = getProp($res,'errcode',"");
+            if (intval($errcode) ==  65303){
+                $res = $app->menu->create($val->content);
+            }
+            myLog('wx-meun')->info(['res' => $res]);
+            $wxMenuId = getProp($res, 'menuid', "");
+            $res = $app->menu->create($val->content, $matchRule);
+            myLog('wx-meun')->info(['res' => $res,'mid' => $wxMenuId]);
+            if ($wxMenuId) {
+                WechatAccountMenuDetail::query()->where('id', $val->id)->update(['wx_menuid' => $wxMenuId]);
+            }
         }
         }
         return true;
         return true;
     }
     }
 
 
+    public static function getofficialAccount($id)
+    {
+        $info = WechatOpenPlatformService::getAppInfoById($id);
+        $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($info->component_appid);
+        $openPlatform = WechatOpenPlatformService::buildApplication($componentInfo);
+        $app = $openPlatform->officialAccount($info->authorizer_appid, getProp($info, 'authorizer_refresh_token'));
+        unset($appInfo);
+        return $app;
+    }
+
+
     /**
     /**
      * 菜单详情
      * 菜单详情
      * name: detail
      * name: detail
@@ -147,6 +183,13 @@ class WechatMenuService extends BaseService
         $info = WechatAccountMenuDetail::query()->whereIn('id', $applyIds)->get();
         $info = WechatAccountMenuDetail::query()->whereIn('id', $applyIds)->get();
         foreach ($info as $val) {
         foreach ($info as $val) {
 
 
+            if ($val->wx_menuid) {
+                // 有菜单则删除菜单
+                $app = self::getofficialAccount($val->wechat_authorization_info_id);
+                $app->menu->delete($info->wx_menuid);
+            }
+
+            WechatAccountMenuDetail::query()->where('wechat_authorization_info_id', $val->id)->update(['wx_menuid' => ""]);
         }
         }
         return "操作成功";
         return "操作成功";
     }
     }
@@ -165,10 +208,10 @@ class WechatMenuService extends BaseService
             self::throwErrMsg('该菜单不存在或已删除');
             self::throwErrMsg('该菜单不存在或已删除');
         }
         }
         // 已分配的
         // 已分配的
-        $appIds = WechatAccountMenuDetail::where(['status' => 1, 'meun_id' => $info->id])->pluck('id')->toArray();
+        $appIds = WechatAccountMenuDetail::where(['status' => 1, 'menu_id' => $info->id])->pluck('wechat_authorization_info_id')->toArray();
         $list = [];
         $list = [];
         $delAppId = [];
         $delAppId = [];
-        $createAddIp  = [];
+        $createAddIp = [];
 
 
         if (empty($wxAuthIds)) {
         if (empty($wxAuthIds)) {
             $data['wechat_accounts'] = [];
             $data['wechat_accounts'] = [];
@@ -188,16 +231,18 @@ class WechatMenuService extends BaseService
             if (count($canNotUsed) > 0) {
             if (count($canNotUsed) > 0) {
                 self::throwErrMsg("优化师对id:为:" . implode(',', $canNotUsed) . "的公众号没有使用权限");
                 self::throwErrMsg("优化师对id:为:" . implode(',', $canNotUsed) . "的公众号没有使用权限");
             }
             }
-            foreach ($appIds as  $val){
-                if (!in_array($val,$wxAuthIds)){
+            foreach ($appIds as $val) {
+                if (!in_array($val, $wxAuthIds)) {
                     $delAppId[] = $val;
                     $delAppId[] = $val;
                 }
                 }
             }
             }
-            $allSet = WechatAccountMenuDetail::query()->where('user_id', $info->user_id)->get();
+            // $allSet = WechatAccountMenuDetail::query()->where('user_id', $info->user_id)->get();
+
             foreach ($wechatAccountInfos as $val) {
             foreach ($wechatAccountInfos as $val) {
-                if (in_array($val->id,$appIds)){
+                if (!in_array($val->id, $appIds)) {
                     $createAddIp[] = $val->id;
                     $createAddIp[] = $val->id;
                 }
                 }
+
                 $data['wechat_accounts'][] = [
                 $data['wechat_accounts'][] = [
                     'id' => $val->id,
                     'id' => $val->id,
                     'appid' => $val->authorizer_appid,
                     'appid' => $val->authorizer_appid,
@@ -206,7 +251,7 @@ class WechatMenuService extends BaseService
                 ];
                 ];
                 $appIds[] = $val->authorizer_appid;
                 $appIds[] = $val->authorizer_appid;
                 $list[] = [
                 $list[] = [
-                    'meun_id' => $info->id,
+                    'menu_id' => $info->id,
                     'user_id' => $info->user_id,
                     'user_id' => $info->user_id,
                     'puser_id' => $info->puser_id,
                     'puser_id' => $info->puser_id,
                     'miniprogram_id' => $info->miniprogram_id,
                     'miniprogram_id' => $info->miniprogram_id,
@@ -214,37 +259,41 @@ class WechatMenuService extends BaseService
                     'wechat_authorization_info_id' => $val->id,
                     'wechat_authorization_info_id' => $val->id,
                     'nick_name' => $val->nick_name,
                     'nick_name' => $val->nick_name,
                     'content' => $info->content,
                     'content' => $info->content,
-                    'msg_content' =>  $info->msg_content,
+                    'msg_content' => $info->msg_content,
                     'status' => 1,
                     'status' => 1,
                 ];
                 ];
             }
             }
-            unset($wechatAccountInfos,$appIds,$val,$canNotUsed);
+            unset($wechatAccountInfos, $appIds, $val, $canNotUsed);
         }
         }
         DB::beginTransaction();
         DB::beginTransaction();
         try {
         try {
-            if (!empty($delAppId)){
-                WechatAccountMenuDetail::whereIn('id',$delAppId)->update(['status' => 0]);
-                foreach ($list as $val){
+            if (!empty($list)) {
+                foreach ($list as $val) {
                     WechatAccountMenuDetail::updateOrCreate(
                     WechatAccountMenuDetail::updateOrCreate(
                         [
                         [
-                            'meun_id' => $val['meun_id'],
+                            'menu_id' => $val['menu_id'],
                             'miniprogram_id' => $val['miniprogram_id'],
                             'miniprogram_id' => $val['miniprogram_id'],
                             'wechat_authorization_info_id' => $val['wechat_authorization_info_id']
                             'wechat_authorization_info_id' => $val['wechat_authorization_info_id']
-                        ],$val);
+                        ], $val);
+
                 }
                 }
-            }else{
-                WechatAccountMenuDetail::where('meun_id',$id)->update(['status' => 0]);
+            } else {
+                WechatAccountMenuDetail::where('menu_id', $id)->update(['status' => 0]);
             }
             }
-            WechatMenu::query()->where('id',$id)->update($data);
+            if (!empty($delAppId)) {
+                WechatAccountMenuDetail::whereIn('id', $delAppId)->update(['status' => 0]);
+            }
+            WechatMenu::query()->where('id', $id)->update($data);
             DB::commit();
             DB::commit();
-        }catch (\Exception $exception){
+        } catch (\Exception $exception) {
             self::throwErrMsg('操作失败');
             self::throwErrMsg('操作失败');
         }
         }
-        if (!empty($createAddIp)){
-            self::createWechatMenus($createAddIp);
+        myLog('wx-meun')->info(['c' => $createAddIp,'del' => $delAppId]);
+        if (!empty($createAddIp)) {
+            self::createWechatMenus($createAddIp,$id);
         }
         }
-        if(!empty($delAppId)){
-            self::delWechatAccountMenu($delAppId);
+        if (!empty($delAppId)) {
+            self::delWechatAccountMenuByMeunId($delAppId,$id);
         }
         }
         return ['msg' => "操作成功"];
         return ['msg' => "操作成功"];
     }
     }
@@ -257,19 +306,19 @@ class WechatMenuService extends BaseService
      */
      */
     public static function list(array $param)
     public static function list(array $param)
     {
     {
-        $sql = self::getQuery($param)->orderBy('id','desc');
-        $isAll = getProp($param,'is_all',false);
-        if($isAll){
+        $sql = self::getQuery($param)->orderBy('id', 'desc');
+        $isAll = getProp($param, 'is_all', false);
+        if ($isAll) {
             $list = $sql->get();
             $list = $sql->get();
-        }else{
-            $list = $sql->paginate(getProp($param,'limit',10));
+        } else {
+            $list = $sql->paginate(getProp($param, 'limit', 10));
         }
         }
         return $list;
         return $list;
     }
     }
 
 
     private static function getQuery(array $param)
     private static function getQuery(array $param)
     {
     {
-        $sql = WechatMenu::query()->where('is_del',0);
+        $sql = WechatMenu::query()->where('is_del', 0);
         if (getProp($param, 'puser_id')) {
         if (getProp($param, 'puser_id')) {
             $sql->where('puser_id', $param['puser_id']);
             $sql->where('puser_id', $param['puser_id']);
         }
         }
@@ -279,13 +328,30 @@ class WechatMenuService extends BaseService
         if (getProp($param, 'keyword')) {
         if (getProp($param, 'keyword')) {
             $sql->where('keyword', "like", "%" . $param['keyword'] . "%");
             $sql->where('keyword', "like", "%" . $param['keyword'] . "%");
         }
         }
-        if(getProp($param,'miniprogram_id')){
-            $sql->where('miniprogram_id',  $param['miniprogram_id']);
+        if (getProp($param, 'miniprogram_id')) {
+            $sql->where('miniprogram_id', $param['miniprogram_id']);
         }
         }
-        if(getProp($param,'wechat_authorization_info_id')){
-            $sql->whereJsonContains('wechat_accounts->id',$param['wechat_authorization_info_id']);
+        if (getProp($param, 'wechat_authorization_info_id')) {
+            $sql->whereJsonContains('wechat_accounts->id', $param['wechat_authorization_info_id']);
         }
         }
         return $sql;
         return $sql;
     }
     }
 
 
+    private static function delWechatAccountMenuByMeunId(array $delAppId, $menuId)
+    {
+        $info = WechatAccountMenuDetail::query()->whereIn('wechat_authorization_info_id', $delAppId)->where('menu_id',$menuId)->get();
+
+        foreach ($info as $val) {
+
+            if ($val->wx_menuid) {
+                // 有菜单则删除菜单
+                $app = self::getofficialAccount($info->wechat_authorization_info_id);
+                $app->menu->delete($val->wx_menuid);
+            }
+
+            WechatAccountMenuDetail::query()->where('wechat_authorization_info_id', $val->id)->update(['wx_menuid' => ""]);
+        }
+        return "操作成功";
+    }
+
 }
 }

+ 1 - 1
modules/WechatPlatform/Services/WechatSubscribeService.php

@@ -282,7 +282,7 @@ class WechatSubscribeService extends BaseService
             return "";
             return "";
         }
         }
         $set = self::getConfig($info->user_id,$info->puser_id,$info->miniprogram_id);
         $set = self::getConfig($info->user_id,$info->puser_id,$info->miniprogram_id);
-        if (getProp($set['data'] == 0)){
+        if (getProp($set,'data') == 0){
             return  '';
             return  '';
         }
         }
         WechatAccountSubscribeDetail::where('id', $info->id)->increment('send_total', 1);
         WechatAccountSubscribeDetail::where('id', $info->id)->increment('send_total', 1);

+ 1 - 0
modules/WechatPlatform/routes/route.php

@@ -92,6 +92,7 @@ Route::prefix('wechatPlatform')->group(function(){
         Route::post('allocation/{id}',[WechatMenuController::class,'allocation']);
         Route::post('allocation/{id}',[WechatMenuController::class,'allocation']);
         // 公众号配置选择项
         // 公众号配置选择项
         Route::any("auth_list/{id}",[WechatMenuController::class,'authList']);
         Route::any("auth_list/{id}",[WechatMenuController::class,'authList']);
+        // 测试
         Route::any("test",[WechatMenuController::class,'test']);
         Route::any("test",[WechatMenuController::class,'test']);
     });
     });