|
@@ -11,6 +11,7 @@ namespace Modules\WechatPlatform\Services;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Modules\Common\Services\BaseService;
|
|
|
+use Modules\WechatPlatform\Models\MiniprogramWechatGlobalConfig;
|
|
|
use Modules\WechatPlatform\Models\WechatAccountKeywordLog;
|
|
|
use Modules\WechatPlatform\Models\WechatKeywords;
|
|
|
|
|
@@ -18,6 +19,7 @@ class WechatKeywordsService extends BaseService
|
|
|
{
|
|
|
|
|
|
protected static array $hideField = ['updated_at', 'is_del', 'del_at', 'user_id', 'puser_id', 'send_content']; // 公用的影藏字段
|
|
|
+ const KEYWORD_SET_KEY = "miniprogram_wechat_keyword";
|
|
|
|
|
|
/**
|
|
|
* 添加关键字
|
|
@@ -96,30 +98,15 @@ class WechatKeywordsService extends BaseService
|
|
|
if (is_empty($info)) {
|
|
|
self::throwErrMsg('关键词不存在或已删除');
|
|
|
}
|
|
|
+ $appIds = [];
|
|
|
if ($param['keyword'] != $info->keyword) {
|
|
|
// 修改关键词,需要查询词关键词是否已配置
|
|
|
- if ($info->wechat_accounts) {
|
|
|
- $appIds = WechatAccountKeywordLog::where('weacht_keyworld_id', $info->id)->where('status', 1)->pluck('appid')->get();
|
|
|
- if ($appIds) {
|
|
|
- $hasUsed = WechatAccountKeywordLog::where('keyword', $param['keyword'])->whereIn('appid', $appIds)->where('status', 1)->pluck('nick_name')->get();
|
|
|
- if ($hasUsed) {
|
|
|
- self::throwErrMsg("关键字{$param['keyword']}已配置了以下公众号" . implode(',', $hasUsed) . "请先解绑后再编辑");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ $appIds = WechatAccountKeywordLog::where('weacht_keyworld_id', $info->id)->where('status', 1)->pluck('wechat_authorization_info_id')->toArray();
|
|
|
}
|
|
|
- DB::beginTransaction();
|
|
|
- try {
|
|
|
- $info->save($param);
|
|
|
- $data = [
|
|
|
- 'content' => $param['send_content'],
|
|
|
- 'keyword' => $param['keyword'],
|
|
|
- ];
|
|
|
- WechatAccountKeywordLog::where('weacht_keyworld_id', $info->id)->update($data);
|
|
|
- DB::commit();
|
|
|
- } catch (\Exception $exception) {
|
|
|
- DB::rollBack();
|
|
|
- self::throwErrMsg('编辑失败');
|
|
|
+ $info->save($param);
|
|
|
+ if ($appIds){
|
|
|
+ WechatAccountKeywordLog::where('weacht_keyworld_id',$info->id)->update(['status' => 0]);
|
|
|
+ self::allocation($info->id,$appIds);
|
|
|
}
|
|
|
return "操作成功";
|
|
|
}
|
|
@@ -184,6 +171,7 @@ class WechatKeywordsService extends BaseService
|
|
|
}
|
|
|
$data = [];
|
|
|
$list = [];
|
|
|
+ $errMsg = "";
|
|
|
if (empty($wxAuthIds)){
|
|
|
$data['wechat_accounts'] = [];
|
|
|
}else{
|
|
@@ -201,6 +189,9 @@ class WechatKeywordsService extends BaseService
|
|
|
if (count($canNotUsed) > 0){
|
|
|
self::throwErrMsg("优化师对id:为:".implode(',',$canNotUsed)."的公众号没有使用权限");
|
|
|
}
|
|
|
+ $keywords = explode(',',$info->keyword);
|
|
|
+
|
|
|
+ $allSet = WechatAccountKeywordLog::where('user_id',$info->user_id)->get();
|
|
|
|
|
|
foreach ($wechatAccountInfos as $val){
|
|
|
$data['wechat_accounts'][] = [
|
|
@@ -209,34 +200,65 @@ class WechatKeywordsService extends BaseService
|
|
|
'nick_name' => $val->nick_name,
|
|
|
'component_appid' => $val->component_appid
|
|
|
];
|
|
|
- $list[] = [
|
|
|
- 'weacht_keyworld_id' => $info->id,
|
|
|
- 'appid' => $val->authorizer_appid,
|
|
|
- 'wechat_authorization_info_id'=> $val->id,
|
|
|
- 'nick_name' => $val->nick_name,'keyword' => $info->keyword,
|
|
|
- 'content' => $info->send_content,
|
|
|
- 'status' => 1,
|
|
|
- ];
|
|
|
+ foreach ($keywords as $kval){
|
|
|
+ $has = $allSet->where( 'keyword',$kval)
|
|
|
+ ->where( 'wechat_authorization_info_id', $val->id)
|
|
|
+ ->where( 'status', 1)
|
|
|
+ ->where('weacht_keyworld_id','<>',$info->id)->first();
|
|
|
+ if ($has){
|
|
|
+ $errMsg .= "{$val->nick_name}已重新配置关键词{$kval};";
|
|
|
+ }
|
|
|
+ $list[] = [
|
|
|
+ 'weacht_keyworld_id' => $info->id,
|
|
|
+ 'user_id' => $info->user_id,
|
|
|
+ 'puser_id' => $info->puser_id,
|
|
|
+ 'miniprogram_id' => $info->miniprogram_id,
|
|
|
+ 'appid' => $val->authorizer_appid,
|
|
|
+ 'wechat_authorization_info_id'=> $val->id,
|
|
|
+ 'nick_name' => $val->nick_name,
|
|
|
+ 'keyword' => $kval,
|
|
|
+ 'content' => $info->send_content,
|
|
|
+ 'status' => 1,
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ unset($wechatAccountInfos,$allSet);
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
+ WechatAccountKeywordLog::where('weacht_keyworld_id',$id)->update(['status' => 0]);
|
|
|
if (!empty($list)){
|
|
|
+ WechatAccountKeywordLog::where('user_id',$info->user_id)
|
|
|
+ ->whereIn("keyword",$keywords)->whereIn('wechat_authorization_info_id',$wxAuthIds)->update(['status' => 0]);
|
|
|
foreach ($list as $val){
|
|
|
- WechatAccountKeywordLog::updateOrCreate(['weacht_keyworld_id' => $val['weacht_keyworld_id'],'wechat_authorization_info_id' => $val['wechat_authorization_info_id']],$val);
|
|
|
+ WechatAccountKeywordLog::updateOrCreate(['weacht_keyworld_id' => $val['weacht_keyworld_id'],'keyword' => $val['keyword'],'wechat_authorization_info_id' => $val['wechat_authorization_info_id']],$val);
|
|
|
}
|
|
|
- }else{
|
|
|
- WechatAccountKeywordLog::where('weacht_keyworld_id',$id)->update(['status' => 0]);
|
|
|
}
|
|
|
WechatKeywords::where('id',$id)->update($data);
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
- DB::rollBack();
|
|
|
self::throwErrMsg('操作失败');
|
|
|
}
|
|
|
- return "操作成功";
|
|
|
+ return "操作成功".$errMsg;
|
|
|
}
|
|
|
|
|
|
+ public static function getConfig($userId, $puserId, $miniprogramId)
|
|
|
+ {
|
|
|
+ $set = MiniprogramWechatGlobalConfig::where(['user_id' => $userId,'puser_id' => $puserId,'miniprogram_id' => $miniprogramId])
|
|
|
+ ->where('type',self::KEYWORD_SET_KEY)->value('value');
|
|
|
+ return $set == 1 ? 1 :0;
|
|
|
+ }
|
|
|
|
|
|
+ public static function setConfig($param)
|
|
|
+ {
|
|
|
+ $param['type'] = self::KEYWORD_SET_KEY;
|
|
|
+ $res = MiniprogramWechatGlobalConfig::updateOrCreate(
|
|
|
+ ['user_id' => $param['user_id'],'puser_id' => $param['puser_id'],'miniprogram_id' => $param['miniprogram_id'],'type' => self::KEYWORD_SET_KEY],
|
|
|
+ $param
|
|
|
+ );
|
|
|
+ if($res){
|
|
|
+ return "操作成功";
|
|
|
+ }
|
|
|
+ return "操作失败";
|
|
|
+ }
|
|
|
}
|