|
@@ -44,12 +44,12 @@ class WechatKeywordsService extends BaseService
|
|
*/
|
|
*/
|
|
public static function getKeywordsList(array $param)
|
|
public static function getKeywordsList(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));
|
|
}
|
|
}
|
|
$list->makeHidden(self::$hideField);
|
|
$list->makeHidden(self::$hideField);
|
|
return $list;
|
|
return $list;
|
|
@@ -57,7 +57,7 @@ class WechatKeywordsService extends BaseService
|
|
|
|
|
|
private static function getQuery(array $param)
|
|
private static function getQuery(array $param)
|
|
{
|
|
{
|
|
- $sql = WechatKeywords::query()->where('is_del',0);
|
|
|
|
|
|
+ $sql = WechatKeywords::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']);
|
|
}
|
|
}
|
|
@@ -67,11 +67,11 @@ class WechatKeywordsService 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;
|
|
}
|
|
}
|
|
@@ -84,7 +84,7 @@ class WechatKeywordsService extends BaseService
|
|
*/
|
|
*/
|
|
public static function detail($id)
|
|
public static function detail($id)
|
|
{
|
|
{
|
|
- return WechatKeywords::where('id', $id)->where('is_del', 0)->first()->makeHidden(array_merge(self::$hideField,['wechat_accounts']));
|
|
|
|
|
|
+ return WechatKeywords::where('id', $id)->where('is_del', 0)->first()->makeHidden(array_merge(self::$hideField, ['wechat_accounts']));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -106,10 +106,10 @@ class WechatKeywordsService extends BaseService
|
|
// 修改关键词,需要查询词关键词是否已配置
|
|
// 修改关键词,需要查询词关键词是否已配置
|
|
$appIds = WechatAccountKeywordLog::where('weacht_keyworld_id', $info->id)->where('status', 1)->pluck('wechat_authorization_info_id')->toArray();
|
|
$appIds = WechatAccountKeywordLog::where('weacht_keyworld_id', $info->id)->where('status', 1)->pluck('wechat_authorization_info_id')->toArray();
|
|
}
|
|
}
|
|
- WechatKeywords::query()->where('id',$id)->update($param);
|
|
|
|
- if ($appIds){
|
|
|
|
- WechatAccountKeywordLog::where('weacht_keyworld_id',$info->id)->update(['status' => 0]);
|
|
|
|
- self::allocation($info->id,$appIds);
|
|
|
|
|
|
+ WechatKeywords::query()->where('id', $id)->update($param);
|
|
|
|
+ if ($appIds) {
|
|
|
|
+ WechatAccountKeywordLog::where('weacht_keyworld_id', $info->id)->update(['status' => 0]);
|
|
|
|
+ self::allocation($info->id, $appIds);
|
|
}
|
|
}
|
|
return "操作成功";
|
|
return "操作成功";
|
|
}
|
|
}
|
|
@@ -175,49 +175,49 @@ class WechatKeywordsService extends BaseService
|
|
$data = [];
|
|
$data = [];
|
|
$list = [];
|
|
$list = [];
|
|
$errMsg = "";
|
|
$errMsg = "";
|
|
- if (empty($wxAuthIds)){
|
|
|
|
|
|
+ if (empty($wxAuthIds)) {
|
|
$data['wechat_accounts'] = [];
|
|
$data['wechat_accounts'] = [];
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
$wechatAccountInfos = DB::table('wechat_authorization_infos')
|
|
$wechatAccountInfos = DB::table('wechat_authorization_infos')
|
|
- ->whereIn('id',$wxAuthIds)
|
|
|
|
- ->where('is_enabled',1)
|
|
|
|
- ->where('user_id',$info->user_id)
|
|
|
|
|
|
+ ->whereIn('id', $wxAuthIds)
|
|
|
|
+ ->where('is_enabled', 1)
|
|
|
|
+ ->where('user_id', $info->user_id)
|
|
->get();
|
|
->get();
|
|
- if($wechatAccountInfos->isEmpty()){
|
|
|
|
|
|
+ if ($wechatAccountInfos->isEmpty()) {
|
|
self::throwErrMsg("优化师对提交的公众号没有使用权限");
|
|
self::throwErrMsg("优化师对提交的公众号没有使用权限");
|
|
}
|
|
}
|
|
|
|
|
|
$canNotUsed = $wechatAccountInfos->pluck('id')->toArray();
|
|
$canNotUsed = $wechatAccountInfos->pluck('id')->toArray();
|
|
- $canNotUsed = array_diff($wxAuthIds,$canNotUsed);
|
|
|
|
- if (count($canNotUsed) > 0){
|
|
|
|
- self::throwErrMsg("优化师对id:为:".implode(',',$canNotUsed)."的公众号没有使用权限");
|
|
|
|
|
|
+ $canNotUsed = array_diff($wxAuthIds, $canNotUsed);
|
|
|
|
+ if (count($canNotUsed) > 0) {
|
|
|
|
+ self::throwErrMsg("优化师对id:为:" . implode(',', $canNotUsed) . "的公众号没有使用权限");
|
|
}
|
|
}
|
|
- $keywords = explode(',',$info->keyword);
|
|
|
|
|
|
+ $keywords = explode(',', $info->keyword);
|
|
|
|
|
|
- $allSet = WechatAccountKeywordLog::where('user_id',$info->user_id)->get();
|
|
|
|
|
|
+ $allSet = WechatAccountKeywordLog::where('user_id', $info->user_id)->get();
|
|
|
|
|
|
- foreach ($wechatAccountInfos as $val){
|
|
|
|
|
|
+ foreach ($wechatAccountInfos as $val) {
|
|
$data['wechat_accounts'][] = [
|
|
$data['wechat_accounts'][] = [
|
|
- 'id' => $val->id,
|
|
|
|
- 'appid' =>$val->authorizer_appid,
|
|
|
|
|
|
+ 'id' => $val->id,
|
|
|
|
+ 'appid' => $val->authorizer_appid,
|
|
'nick_name' => $val->nick_name,
|
|
'nick_name' => $val->nick_name,
|
|
'component_appid' => $val->component_appid
|
|
'component_appid' => $val->component_appid
|
|
];
|
|
];
|
|
- 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};";
|
|
|
|
|
|
+ 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[] = [
|
|
$list[] = [
|
|
'weacht_keyworld_id' => $info->id,
|
|
'weacht_keyworld_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,
|
|
'appid' => $val->authorizer_appid,
|
|
'appid' => $val->authorizer_appid,
|
|
- 'wechat_authorization_info_id'=> $val->id,
|
|
|
|
|
|
+ 'wechat_authorization_info_id' => $val->id,
|
|
'nick_name' => $val->nick_name,
|
|
'nick_name' => $val->nick_name,
|
|
'keyword' => $kval,
|
|
'keyword' => $kval,
|
|
'content' => $info->send_content,
|
|
'content' => $info->send_content,
|
|
@@ -225,43 +225,67 @@ class WechatKeywordsService extends BaseService
|
|
];
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- unset($wechatAccountInfos,$allSet);
|
|
|
|
|
|
+ unset($wechatAccountInfos, $allSet);
|
|
}
|
|
}
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
try {
|
|
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'],'keyword' => $val['keyword'],'wechat_authorization_info_id' => $val['wechat_authorization_info_id']],$val);
|
|
|
|
|
|
+ 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'], 'keyword' => $val['keyword'], 'wechat_authorization_info_id' => $val['wechat_authorization_info_id']], $val);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- WechatKeywords::where('id',$id)->update($data);
|
|
|
|
|
|
+ WechatKeywords::where('id', $id)->update($data);
|
|
DB::commit();
|
|
DB::commit();
|
|
- }catch (\Exception $exception){
|
|
|
|
|
|
+ } catch (\Exception $exception) {
|
|
self::throwErrMsg('操作失败');
|
|
self::throwErrMsg('操作失败');
|
|
}
|
|
}
|
|
- return "操作成功".$errMsg;
|
|
|
|
|
|
+ return "操作成功" . $errMsg;
|
|
}
|
|
}
|
|
|
|
|
|
public static function getConfig($userId, $puserId, $miniprogramId)
|
|
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;
|
|
|
|
|
|
+ $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)
|
|
public static function setConfig($param)
|
|
{
|
|
{
|
|
$param['type'] = self::KEYWORD_SET_KEY;
|
|
$param['type'] = self::KEYWORD_SET_KEY;
|
|
$res = MiniprogramWechatGlobalConfig::updateOrCreate(
|
|
$res = MiniprogramWechatGlobalConfig::updateOrCreate(
|
|
- ['user_id' => $param['user_id'],'puser_id' => $param['puser_id'],'miniprogram_id' => $param['miniprogram_id'],'type' => self::KEYWORD_SET_KEY],
|
|
|
|
|
|
+ ['user_id' => $param['user_id'], 'puser_id' => $param['puser_id'], 'miniprogram_id' => $param['miniprogram_id'], 'type' => self::KEYWORD_SET_KEY],
|
|
$param
|
|
$param
|
|
);
|
|
);
|
|
- if($res){
|
|
|
|
|
|
+ if ($res) {
|
|
return "操作成功";
|
|
return "操作成功";
|
|
}
|
|
}
|
|
return "操作失败";
|
|
return "操作失败";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新关键词,授权公众号id匹配关键词
|
|
|
|
+ * name: getKeywordsByWords
|
|
|
|
+ * @param $keyword
|
|
|
|
+ * @param $wechatAppId
|
|
|
|
+ * @return mixed|string
|
|
|
|
+ * date 2023/07/10 16:31
|
|
|
|
+ */
|
|
|
|
+ public static function getKeywordsByWords($keyword, $wechatAppId)
|
|
|
|
+ {
|
|
|
|
+ // 匹配关键词
|
|
|
|
+ $info = WechatAccountKeywordLog::where(["
|
|
|
|
+ keyword" => $keyword,
|
|
|
|
+ 'status' => 1,
|
|
|
|
+ 'wechat_authorization_info_id' => $wechatAppId,
|
|
|
|
+ ])->first();
|
|
|
|
+ if (is_empty($info)) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ WechatAccountKeywordLog::where('id', $info->id)->increment('send_total', 1);
|
|
|
|
+ WechatKeywords::where('id', $info->weacht_keyworld_id)->increment('send_total', 1);
|
|
|
|
+ return $info->content;
|
|
|
|
+ }
|
|
}
|
|
}
|