diff --git a/backend/modules/wx_public_account/logic/PublicAccountManager.php b/backend/modules/wx_public_account/logic/PublicAccountManager.php index d49ea73..e302641 100644 --- a/backend/modules/wx_public_account/logic/PublicAccountManager.php +++ b/backend/modules/wx_public_account/logic/PublicAccountManager.php @@ -1,32 +1,26 @@ one(); - if (!$configModel || !$configModel->) - $config = [ - 'app_id' => - ]; - } - /** + * 处理前端自定义菜单数据 * @param $data - * @param Config|$configModel + * @param WxPublicAccountConfig|$configModel + * @return bool * @throws ServerErrorHttpException */ public static function dealCustomMenuData($data, $configModel) @@ -37,12 +31,30 @@ class PublicAccountManager if (!$configModel->save()) { throw new Exception(self::dealSaveErrorsString($configModel->errors)); } - $button = self + $button = self::dealData($data, []); + $res = self::$openPlatform->menu->delete(); + if ($res['errcode'] != 0) { + throw new Exception($res['errmsg']); + } + if ($button) { + $res = self::$openPlatform->menu->create($button); + if ($res['errcode'] != 0) { + throw new Exception($res['errmsg']); + } + } + $tra->commit(); + return ['status' => true]; } catch (Exception $e) { - throw new ServerErrorHttpException($e->getMessage()); + $tra->rollBack(); + return ['status' => false, 'info' => $e->getMessage()]; } } + /** + * 处理数据模型保存的报错信息 + * @param $arr + * @return string + */ public static function dealSaveErrorsString($arr): string { $data = []; @@ -53,10 +65,10 @@ class PublicAccountManager } /** + * 处理前端数据,递归处理 * @param $data * @param $ret * @return mixed - * 处理前端数据,递归处理 */ private static function dealData($data, $ret) { @@ -75,11 +87,11 @@ class PublicAccountManager } /** + * 拼接数据为微信菜单格式 * @param $type * @param $value * @param $name * @return mixed - * 拼接数据为微信菜单格式 */ private static function spliceData($type, $value, $name) {