|
@@ -49,7 +49,6 @@ class WechatMenuService extends BaseService
|
|
if (is_empty($info)) {
|
|
if (is_empty($info)) {
|
|
self::throwErrMsg('该菜单不存在或已删除');
|
|
self::throwErrMsg('该菜单不存在或已删除');
|
|
}
|
|
}
|
|
- $appIds = WechatAccountMenuDetail::where(['status' => 1, 'menu_id' => $info->id])->pluck('id')->toArray();
|
|
|
|
WechatMenu::where('id', $id)->update($param);
|
|
WechatMenu::where('id', $id)->update($param);
|
|
$data = [
|
|
$data = [
|
|
'type' => $param['type'],
|
|
'type' => $param['type'],
|
|
@@ -58,34 +57,47 @@ class WechatMenuService extends BaseService
|
|
];
|
|
];
|
|
WechatAccountMenuDetail::where('menu_id', $id)->update($data);
|
|
WechatAccountMenuDetail::where('menu_id', $id)->update($data);
|
|
// 更新公众号菜单
|
|
// 更新公众号菜单
|
|
- self::createWechatMenus($appIds);
|
|
|
|
|
|
+ $appIds = WechatAccountMenuDetail::where(['status' => 1, 'menu_id' => $info->id])->pluck('wechat_authorization_info_id')->toArray();
|
|
|
|
+ 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($info->wechat_authorization_info_id);
|
|
|
|
|
|
+ $app = self::getofficialAccount($val->wechat_authorization_info_id);
|
|
if ($val->wx_menuid) {
|
|
if ($val->wx_menuid) {
|
|
// 有菜单则删除菜单
|
|
// 有菜单则删除菜单
|
|
- $app->menu->delete($info->wx_menuid);
|
|
|
|
|
|
+ $app->menu->delete($val->wx_menuid);
|
|
}
|
|
}
|
|
$matchRule = [
|
|
$matchRule = [
|
|
- "client_platform_type" => $info->type == "iso" ? "1" : "2",
|
|
|
|
|
|
+ "client_platform_type" => $val->type == "ios" ? "1" : "2",
|
|
];
|
|
];
|
|
- $res = $app->menu->create($info->content, $matchRule);
|
|
|
|
|
|
+ $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', "");
|
|
$wxMenuId = getProp($res, 'menuid', "");
|
|
|
|
+ $res = $app->menu->create($val->content, $matchRule);
|
|
|
|
+ myLog('wx-meun')->info(['res' => $res,'mid' => $wxMenuId]);
|
|
if ($wxMenuId) {
|
|
if ($wxMenuId) {
|
|
WechatAccountMenuDetail::query()->where('id', $val->id)->update(['wx_menuid' => $wxMenuId]);
|
|
WechatAccountMenuDetail::query()->where('id', $val->id)->update(['wx_menuid' => $wxMenuId]);
|
|
}
|
|
}
|
|
@@ -173,11 +185,11 @@ class WechatMenuService extends BaseService
|
|
|
|
|
|
if ($val->wx_menuid) {
|
|
if ($val->wx_menuid) {
|
|
// 有菜单则删除菜单
|
|
// 有菜单则删除菜单
|
|
- $app = self::getofficialAccount($info->wechat_authorization_info_id);
|
|
|
|
|
|
+ $app = self::getofficialAccount($val->wechat_authorization_info_id);
|
|
$app->menu->delete($info->wx_menuid);
|
|
$app->menu->delete($info->wx_menuid);
|
|
}
|
|
}
|
|
|
|
|
|
- WechatAccountMenuDetail::query()->where('id', $val->id)->update(['wx_menuid' => ""]);
|
|
|
|
|
|
+ WechatAccountMenuDetail::query()->where('wechat_authorization_info_id', $val->id)->update(['wx_menuid' => ""]);
|
|
}
|
|
}
|
|
return "操作成功";
|
|
return "操作成功";
|
|
}
|
|
}
|
|
@@ -196,7 +208,7 @@ class WechatMenuService extends BaseService
|
|
self::throwErrMsg('该菜单不存在或已删除');
|
|
self::throwErrMsg('该菜单不存在或已删除');
|
|
}
|
|
}
|
|
// 已分配的
|
|
// 已分配的
|
|
- $appIds = WechatAccountMenuDetail::where(['status' => 1, 'menu_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 = [];
|
|
@@ -225,12 +237,8 @@ class WechatMenuService extends BaseService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// $allSet = WechatAccountMenuDetail::query()->where('user_id', $info->user_id)->get();
|
|
// $allSet = WechatAccountMenuDetail::query()->where('user_id', $info->user_id)->get();
|
|
-
|
|
|
|
|
|
+ $appIds = [];
|
|
foreach ($wechatAccountInfos as $val) {
|
|
foreach ($wechatAccountInfos as $val) {
|
|
- if (!in_array($val->id, $appIds)) {
|
|
|
|
- $createAddIp[] = $val->id;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
$data['wechat_accounts'][] = [
|
|
$data['wechat_accounts'][] = [
|
|
'id' => $val->id,
|
|
'id' => $val->id,
|
|
'appid' => $val->authorizer_appid,
|
|
'appid' => $val->authorizer_appid,
|
|
@@ -263,6 +271,7 @@ class WechatMenuService extends BaseService
|
|
'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 {
|
|
} else {
|
|
WechatAccountMenuDetail::where('menu_id', $id)->update(['status' => 0]);
|
|
WechatAccountMenuDetail::where('menu_id', $id)->update(['status' => 0]);
|
|
@@ -275,11 +284,13 @@ class WechatMenuService extends BaseService
|
|
} catch (\Exception $exception) {
|
|
} catch (\Exception $exception) {
|
|
self::throwErrMsg('操作失败');
|
|
self::throwErrMsg('操作失败');
|
|
}
|
|
}
|
|
|
|
+ $createAddIp = WechatAccountMenuDetail::where(['status' => 1, 'menu_id' => $info->id])->pluck('wechat_authorization_info_id')->toArray();
|
|
|
|
+ myLog('wx-meun')->info(['c' => $createAddIp,'del' => $delAppId]);
|
|
if (!empty($createAddIp)) {
|
|
if (!empty($createAddIp)) {
|
|
- self::createWechatMenus($createAddIp);
|
|
|
|
|
|
+ self::createWechatMenus($createAddIp,$id);
|
|
}
|
|
}
|
|
if (!empty($delAppId)) {
|
|
if (!empty($delAppId)) {
|
|
- self::delWechatAccountMenu($delAppId);
|
|
|
|
|
|
+ self::delWechatAccountMenuByMeunId($delAppId,$id);
|
|
}
|
|
}
|
|
return ['msg' => "操作成功"];
|
|
return ['msg' => "操作成功"];
|
|
}
|
|
}
|
|
@@ -299,6 +310,12 @@ class WechatMenuService extends BaseService
|
|
} else {
|
|
} else {
|
|
$list = $sql->paginate(getProp($param, 'limit', 10));
|
|
$list = $sql->paginate(getProp($param, 'limit', 10));
|
|
}
|
|
}
|
|
|
|
+ foreach ($list as $val){
|
|
|
|
+ $val->wechat_accounts = WechatAccountMenuDetail::query()->where(
|
|
|
|
+ ['subscribe_id' => $val->id,
|
|
|
|
+ 'status' => 1
|
|
|
|
+ ])->select('wechat_authorization_info_id as id',"appid",'nick_name')->get();
|
|
|
|
+ }
|
|
return $list;
|
|
return $list;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -318,9 +335,58 @@ class WechatMenuService extends BaseService
|
|
$sql->where('miniprogram_id', $param['miniprogram_id']);
|
|
$sql->where('miniprogram_id', $param['miniprogram_id']);
|
|
}
|
|
}
|
|
if (getProp($param, 'wechat_authorization_info_id')) {
|
|
if (getProp($param, 'wechat_authorization_info_id')) {
|
|
- $sql->whereJsonContains('wechat_accounts->id', $param['wechat_authorization_info_id']);
|
|
|
|
|
|
+ $ids = WechatAccountMenuDetail::query()->where([
|
|
|
|
+ 'wechat_authorization_info_id' => $param['wechat_authorization_info_id'],
|
|
|
|
+ 'status' => 1,
|
|
|
|
+ ])->pluck('weacht_keyworld_id')->toArray();
|
|
}
|
|
}
|
|
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 "操作成功";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 点击事件回复
|
|
|
|
+ * name: getClickInfoContent
|
|
|
|
+ * @param $wechatInfoId
|
|
|
|
+ * date 2023/07/12 16:37
|
|
|
|
+ */
|
|
|
|
+ public static function getClickInfoContent($wechatAppId,$key)
|
|
|
|
+ {
|
|
|
|
+ $info = WechatAccountMenuDetail::query()->where([
|
|
|
|
+ 'status' => 1,
|
|
|
|
+ 'wechat_authorization_info_id' => $wechatAppId,
|
|
|
|
+ ])->first();
|
|
|
|
+ if (is_empty($info)){
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ $content = $info->msg_content;
|
|
|
|
+ if (empty($content)){
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ foreach ($content as $val){
|
|
|
|
+
|
|
|
|
+ if (isset($val[$key])){
|
|
|
|
+ $content = $val[$key];
|
|
|
|
+ break ;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $content ?: "";
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|