setMpKeywordByNews()增加或者修改图文关键词内容 ~~~ /**【增加或者修改图文关键词内容】 * @author geeson rhaphp.com * @param string $keyword 关键词 * @param string $title 标题 * @param string $picurl 封面URL * @param string $desc 描述内容 * @param string $link 连接地址 (不需要域名),接受addonUrl()与 Url()函数地址 * @return bool */ function setMpKeywordByNews($keyword = '', $title = '', $picurl = '', $desc = '', $link = '') { $mp = getMpInfo(); if (!$keyword || !$title || !$picurl || !$desc || !$link || !isset($mp['id'])) { return false;//['status'=>0,'msg'=>'参数缺失']; } $data['mpid'] = $mp['id']; $data['keyword'] = $keyword; $data['title'] = $title; $data['url'] = $picurl; $data['content'] = $desc; $data['link'] = getHostDomain() . $link; $data['type'] = 'news'; $ruleModel = new \app\common\model\MpRule(); $replyMode = new \app\common\model\MpReply(); if ($result = $replyMode->alias('a')->where('a.link', $data['link']) ->join('__MP_RULE__ b', 'b.reply_id=a.reply_id') ->find()) { if ($data['mpid'] != $result['mpid']) { ajaxMsg(0, '回复关键词内容公众号标识与当前公众号标识不匹配'); } $replyMode->allowField(true)->save($data, ['reply_id' => $result['reply_id']]); $ruleModel->allowField(true)->save(['keyword' => $data['keyword']], ['reply_id' => $result['reply_id']]); return true; } else { if ($res_1 = $replyMode->allowField(true)->save($data)) { $data['reply_id'] = $replyMode->reply_id; if (!$res_2 = $ruleModel->allowField(true)->save($data)) { $replyMode::destroy(['reply_id' => $data['reply_id']]); } } if ($res_1 && $res_2) { return $replyMode->reply_id; } else { return false; } } } ~~~