all(); if(!getProp($param,'miniprogram_id')){ WechatKeywordsService::throwErrMsg("参数错误"); } $userContext = $this->getUserContext(null); $param['user_id'] = $userContext['loginUser']->id; $param['puser_id'] = $userContext['loginUser']->pid; return WechatKeywordsService::getKeywordsList($param); } /** * 添加 * name: add * @param WechatKeywordsRequest $request * date 2023/07/05 15:36 */ public function add(WechatKeywordsRequest $request) { $param = $request->validated(); $param = $this->wechatKeywordsParam($param); $userContext = $this->getUserContext(null); $param['user_id'] = $userContext['loginUser']->id; $param['puser_id'] = $userContext['loginUser']->pid; $param['wechat_accounts'] = []; return WechatKeywordsService::addKeyword($param); } private function wechatKeywordsParam(mixed $param) { $info = DB::table('miniprogram')->where('id',$param['miniprogram_id'])->first(); if(empty($info)){ throw new FailedException("小程序不正确"); } if($info->status != 1){ throw new FailedException("此小程序暂不提供使用"); } if ($info->type != MiniprogramType::WEIXIN->value()){ throw new FailedException("关键词回复设置仅支持微信小程序"); } $param['miniprogram_appid'] = $info->appid; $info = DB::table('user_has_miniprograms')->where('uid',$this->getLoginUserId())->where('miniprogram_id',$param['miniprogram_id'])->where('is_enabled',1)->value('id'); if(empty($info)){ throw new FailedException("没有此小程序的使用权限"); } $param['send_content'] = ""; foreach ($param['content'] as & $val){ if (!is_array($val)){ throw new FailedException("回复内容格式不正确"); } if (getProp($val,'url')){ // 跳转小程序 $val['content'] = "{$val['title']}"; }else{ $val['content'] = $val['title']; $val['url'] = ""; } $param['send_content'] .= $val['content']."\n"; } rtrim($param['send_content'],"\n"); return $param; } /** * 编辑 * name: edit * @param $id * @param WechatKeywordsRequest $request * date 2023/07/05 15:36 */ public function edit($id, WechatKeywordsRequest $request) { $param = $request->validated(); $param = $this->wechatKeywordsParam($param); return WechatKeywordsService::updateKeyWords($id,$param); } /** * 详情 * name: detail * @param $id * date 2023/07/05 15:36 */ public function detail($id) { return WechatKeywordsService::detail($id); } /** * 分配 * name: allocation * @param $id * @param Request $request * date 2023/07/05 16:03 */ public function allocation($id,Request $request) { if (!$request->has('wx_auth_ids')){ throw new FailedException("参数错误"); } if (!empty($request->input('wx_auth_ids'))) { $wxAuthIds = explode(',', $request->input('wx_auth_ids')); }else{ $wxAuthIds = []; } return WechatKeywordsService::allocation($id,$wxAuthIds); } /** * 删除 * name: del * @param $id * date 2023/07/05 15:47 */ public function del(Request $request) { $ids = $request->input('ids'); if (empty($ids)){ throw new FailedException('要删除的数据参数错误'); } $ids = explode(',',$ids); return WechatKeywordsService::delKeywords($ids); } /** * 公众号授权列表 * name: authList * @param $id * date 2023/07/06 15:17 */ public function authList($id) { $userId = $this->getLoginUserId(); return WechatKeywordsService::WechaAccountAuthListInfo($id,$userId); } /** * 获取设置 * name: getConfig * @param $miniprogramId * @return int * date 2023/07/10 09:33 */ public function getConfig($miniprogramId) { $userContext = $this->getUserContext(null); $userId = $userContext['loginUser']->id; $puserId = $userContext['loginUser']->pid; return WechatKeywordsService:: getConfig($userId,$puserId,$miniprogramId); } /** * 更新设置 * name: setConfig * @param $miniprogramId * @param Request $request * @return string * date 2023/07/10 09:33 */ public function setConfig($miniprogramId,Request $request) { if (!$request->has('value') ){ throw new FailedException("参数错误"); } $param = $request->all(['value']); if (!in_array($param['value'],[0,1]) ){ throw new FailedException("参数错误"); } $userContext = $this->getUserContext(null); $param['miniprogram_id'] = $miniprogramId; $param['user_id'] = $userContext['loginUser']->id; $param['puser_id'] = $userContext['loginUser']->pid; return WechatKeywordsService::setConfig($param); } }