model = model('Custom'); $this->customMediaModel = model('CustomMedia'); $this->adminConfigModel = model('AdminConfig'); $this->customUrlModel = model('CustomUrl'); $this->customMediaPushModel = model('CustomMediaPush'); $this->referralModel = model('Referral'); $this->bookModel = model('Book'); $this->view->assign("statueList", $this->model->getStatueList()); $this->assign('admin_id', $this->auth->id); $this->assignconfig('admin_id', $this->auth->id); $this->assignconfig('nowtime', time()); $miniOpen = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group); $miniPages = MiniProgramService::instance()->getMiniPage(); $this->assign('miniOpen',$miniOpen); $this->assign('miniPages',$miniPages); } public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) ->order($sort, $order) ->where('created_from', CustomConstants::CUSTOM_CREATED_FROM_ADD) ->count(); $list = $this->model ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->where('created_from', CustomConstants::CUSTOM_CREATED_FROM_ADD) ->select(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 测试发送客服消息 * @param int|array $admin_id 渠道id * @param int $user_id 公众号id * @param string $cdata 素材内容 * @param string $ids 素材id * @param string $msg_type 素材类型 * @return \think\response\Json */ public function sent( $admin_id, $user_id, $cdata = '', $ids = 0, $msg_type = Message::MESSAGE_TYPE_IMAGE_TEXT, $official_type = OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE ) { if ($this->request->get('table') == 'push') { $ids = $this->customMediaPushModel->where(['id' => $ids])->column('custom_media_id'); $ids = array_pop($ids); } if ($official_type == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SUBSCRIPTION) { $params = $this->request->post(); $result = CustomService::instance()->sendMessageSubscribeToUser($admin_id, $params['sub_id'], $user_id, $cdata, $ids, $msg_type); } else { $result = CustomService::instance()->sendMessageServiceToUser((array)$admin_id, $user_id, $cdata, $ids, $msg_type); } return json($result); } /** * 客服消息根据条件筛选会员人数 */ public function ajaxcustomajaxcustom() { return 0; // user分库分表之后无法再统计人数 // $admin_id = $this->auth->id; // $sex = $this->request->post('sex'); // $tag = $this->request->post('tag'); // $consume = $this->request->post('consume'); // $kandian = $this->request->post('kandian'); // $subscribe_time = $this->request->post('subscribe_time'); // $condition = " where channel_id = ".$admin_id; // $condition.= " and state = '1'"; // $condition.= " and is_subscribe = '1' "; // if($sex!=-1){ // $condition.= " and sex = '{$sex}' "; // } // if($tag > 0){ // $condition.= " and FIND_IN_SET(".$tag.",book_category_ids)"; // } // if($consume==1){ //未付款 // $condition.= " and is_pay='0'"; // }elseif($consume == 2){ //普通已付款 // $condition.= " and is_pay='1'"; // }elseif($consume == 3){ //vip会员 // $condition.= " and vip_endtime > ".time(); // } // // if($kandian ==1){ //书币低于500 // $condition.= " and kandian < 500"; // }elseif($kandian == 2){ //书币低于2000 // $condition.= " and kandian < 2000"; // }elseif($kandian == 3){ //书币大于2000 // $condition.= " and kandian >= 2000"; // } // // $oneWeek = time()-86400*7; //一周内 // $twoWeek = time()-86400*14; //两周内 // $oneMonth = time()-86400*30; //一月内 // $twoMonth = time()-86400*60; //两月内 // // if($subscribe_time == 1){ //一周内 // $condition.= " and subscribe_time >= {$oneWeek}"; // }elseif($subscribe_time == 2){ //两周内 // $condition.= " and subscribe_time >= {$twoWeek}"; // }elseif($subscribe_time == 3){ //一月内 // $condition.= " and subscribe_time >= {$oneMonth}"; // }elseif($subscribe_time == 4){ //两月内 // $condition.= " and subscribe_time >= {$twoMonth}"; // }elseif($subscribe_time == 5){ //更早 // $condition.= " and subscribe_time < {$twoMonth}"; // } // // $sql = "select count(id) as ids from user ".$condition; // // $result = model('User')->query($sql); // return json($result[0]); } /** * 异步获取category列表 //客服消息tag标签接口 * @return \think\response\Json */ public function ajaxcategory() { $list = model('BookCategory') ->where('status', '=', 'normal') ->order('weigh', 'desc') ->select(); $categorylist = []; foreach ($list as $key => $value) { if ($value['sex'] == '1') { $sex = '男频'; } else { $sex = '女频'; } $categorylist[] = ['id' => $value['id'], 'name' => $sex . '-' . $value['name']]; } $res = []; $res['data'] = $categorylist; //$ids = model('User')->where(['sex'=>1,'channel_id'=>$this->auth->id])->count(); $res['ids'] = '--'; return json($res); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 添加 */ public function add() { header("Content-Type: text/html;charset=utf-8"); if ($this->request->isPost()) { $params = $this->request->post("row/a"); $params['is_save_media'] = 0; #客服消息为文字链模式时,没有message_json字段 $msgType = $params['message_type']; if ($msgType == Message::MESSAGE_TYPE_IMAGE_TEXT) { $msgContent = !empty($params['message_json']) ? $params['message_json'] : json_encode(array()); } else { $msgContent = !empty($params['message_text']) ? $params['message_text'] : json_encode(array()); } if ($params) { $sendtime = $params['sendtime']; if (strtotime($sendtime) < time()) { $this->error('发送时间不能小于当前时间'); } if ($this->dataLimit) { $params[$this->dataLimitField] = $this->auth->id; } //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; $this->model->validate($validate); } $sendTime = $params['sendtime']; $iAdminId = $this->auth->id; $channelIds = [$this->auth->id]; CustomService::instance()->createPushService($sendTime, $channelIds, $iAdminId, $msgType, $msgContent, 0, $params['is_save_media'] == Common::YES, $params['title'], $params['user_json']); $jumpUrl = ''; if ($params['is_save_media'] == Common::YES) { switch ($msgType) { case Message::MESSAGE_TYPE_IMAGE_TEXT: $jumpUrl = '/admin/messagecustom/imagetextmedia/index?ref=addtabs'; break; case Message::MESSAGE_TYPE_LINK: $jumpUrl = '/admin/messagecustom/linktextmedia/index?ref=addtabs'; break; default: break; } } else { $jumpUrl = '/admin/custom?ref=addtabs'; } $this->success('操作成功', null, ['jump' => $jumpUrl]); } $this->error(__('Parameter %s can not be empty', '')); } $input = $this->request->param(); $addtype = !empty($input['addtype']) ? $input['addtype'] : 'typeimg'; $this->assign('addtype', $addtype); return $this->view->fetch(); } /** * * @return \think\response\Json */ public function autocompletebookname() { if ($this->request->isAjax()) { $keyword = $this->request->post('name') ?? $this->request->param('pkey_value'); $data = []; $keyword = trim($keyword); $bookModel = model('Book'); $map = []; if ($this->group > 2) { $map['cansee'] = 1; } //获取独家书籍id ExclusiveService::instance()->getExclusiveNotidsWithWhere($this->group, $this->auth->id,$map); if (!empty($keyword)) { $bookList = $bookModel ->where('state', 'neq', BookConstants::BOOK_STATE_OFF_SALE) ->where($map) ->where(function (Query $query) use ($keyword) { $query->where('name', 'like', "%{$keyword}%") ->whereOr('id', $keyword); }) ->limit(0, 10)->select(); } else { $bookList = $bookModel->where('state', 'neq', BookConstants::BOOK_STATE_OFF_SALE)->where($map)->order('book.idx desc,book.idxx desc')->limit(0, 10)->select(); } $data = $bookList; return json(['list' => $data, 'total' => count($data)]); } } public function addimagetext() { $channelId = $this->auth->id; if ($this->request->isPost()) { $params = $this->request->post(); $type = $params['row']['imgtxt_type']; $result = ['type' => $type]; if ($type == Message::MESSAGE_LINK_TYPE_BOOK) { $result = array_merge($result, $params['book']); //$result['book_name'] = $params['book_name']; } elseif ($type == Message::MESSAGE_LINK_TYPE_ACTIVITY) { $result = array_merge($result, $params['activity']); } elseif ($type == Message::MESSAGE_LINK_TYPE_RECENT) { $result = array_merge($result, $params['recent']); } elseif ($type == Message::MESSAGE_LINK_TYPE_MENU) { $result = array_merge($result, $params['menu']); } elseif ($type == Message::MESSAGE_LINK_TYPE_NOURL) { $result = array_merge($result, $params['no_url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_URL) { if (strlen($params['url']['url']) > 255) { $this->error("自定义链接最大长度不能超过255个字符"); } $result = array_merge($result, $params['url']); }elseif ($type == Message::MESSAGE_LINK_TYPE_DAILY_LINK) { $result = array_merge($result, $params['daily_url']); } if ($type == Message::MESSAGE_LINK_TYPE_MINI){ $params['mini']['title'] = $params['mini']['title'] ?? '小程序码'; $params['mini']['image'] = $params['mini']['image'] ?? ''; $result = array_merge($result,$params['mini']); $result['url'] = $params['mini']['image']; if ($result['mini_type'] == 3 && empty($result['url'])){ $this->error('图片必须上传'); } } /*$customService = new CustomService(); $url = $customService->buildUrl($channelId, $result); $result['url'] = $url;*/ $this->success('', null, $result); } else { $referralModel = model('Referral'); $wxTypeList = $referralModel->getWxTypeList(); $pushList = $referralModel->getPushList(); $recentUrl = Message::getRecentFullPath($channelId); $aActivity = CommonService::instance()->getValidActivities($this->auth->id); $menuList = []; foreach (Menu::$allLinks as $key => $link) { $menuList[$key] = $link['title']; } //常用链接地址列表 $dailyLink = $this->getCurrentUserDailyLink(); $this->view->assign("dailyLink", $dailyLink); $this->assign('acc_type', Message::MESSAGE_TYPE_IMAGE_TEXT); $this->view->assign("menuList", $menuList); $this->view->assign("wxTypeList", $wxTypeList); $this->view->assign("activityList", $aActivity); $this->view->assign("pushList", $pushList); $this->view->assign("recent_url", $recentUrl); } return $this->view->fetch(); } public function addlinktext() { $channelId = $this->auth->id; if ($this->request->isPost()) { $params = $this->request->post(); $type = $params['row']['imgtxt_type']; $result = ['type' => $type]; if ($type == Message::MESSAGE_LINK_TYPE_BOOK) { $result = array_merge($result, $params['book']); #$result['book_name'] = $params['book_book_id_text']; } elseif ($type == Message::MESSAGE_LINK_TYPE_ACTIVITY) { $result = array_merge($result, $params['activity']); } elseif ($type == Message::MESSAGE_LINK_TYPE_RECENT) { $result = array_merge($result, $params['recent']); } elseif ($type == Message::MESSAGE_LINK_TYPE_MENU) { $result = array_merge($result, $params['menu']); } elseif ($type == Message::MESSAGE_LINK_TYPE_NOURL) { $result = array_merge($result, $params['no_url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_URL) { if (strlen($params['url']['url']) > 255) { $this->error("自定义链接最大长度不能超过255个字符"); } $result = array_merge($result, $params['url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_SIGN) { $params['sign']['url'] = "weixin://bizmsgmenu?msgmenucontent=" . Message::MESSAGE_KEYWORD . "&msgmenuid=" . time(); $result = array_merge($result, $params['sign']); }elseif ($type == Message::MESSAGE_LINK_TYPE_DAILY_LINK) { $result = array_merge($result, $params['daily_url']); }elseif ($type == Message::MESSAGE_LINK_TYPE_MINI){ $result = array_merge($result,$params['mini']); } $this->success('', null, $result); } else { $referralModel = model('Referral'); $wxTypeList = $referralModel->getWxTypeList(); $pushList = $referralModel->getPushList(); $recentUrl = getCurrentDomain($channelId, '/index/user/recent'); $aActivity = CommonService::instance()->getValidActivities($this->auth->id); $menuList = []; foreach (Menu::$allLinks as $key => $link) { $menuList[$key] = $link['title']; } //常用链接地址列表 $dailyLink = $this->getCurrentUserDailyLink(); $this->view->assign("dailyLink", $dailyLink); $this->assign('acc_type', Message::MESSAGE_TYPE_LINK); $this->view->assign("menuList", $menuList); $this->view->assign("wxTypeList", $wxTypeList); $this->view->assign("activityList", $aActivity); $this->view->assign("pushList", $pushList); $this->view->assign("recent_url", $recentUrl); } return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $officialAccountId = $row->official_account_id; $official_account_type = $row->official_account_type; $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } $canEdit = 0; if ($row['sendtime'] <= time()) { //已发送,不能修改 $canEdit = 1; } if ($row['sendtime'] > time() && $row['sendtime'] - time() <= 600) { //发送前10分钟内不能修改 $canEdit = 1; } $this->assign("canedit", $canEdit); if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { if (strtotime($params['sendtime']) < time()) { $this->error('发送时间不能小于当前时间'); } try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate; $row->validate($validate); } #region 更改客服消息 #1. 通过$ids 获取 custom_media_push_id $customData = $this->model->get(['id' => $ids]); $customMediaPushId = $customData->custom_media_push_id; #2. 更新 custom_media_push 表 内容 if (!$params['message_type']) { // 图文 $customMediaPushData = [ 'message_json' => $params['message_json'], 'user_json' => $params['user_json'], 'sendtime' => strtotime($params['sendtime']), 'updatetime' => time() ]; } else { $customMediaPushData = [ 'message_text' => $params['message_text'], 'user_json' => $params['user_json'], 'sendtime' => strtotime($params['sendtime']), 'updatetime' => time() ]; } $this->customMediaPushModel->save($customMediaPushData, ['id' => $customMediaPushId]); $customService = new CustomService(); #3. 更新 custom 表 内容 $customData = [ 'user_json' => $params['user_json'], 'sendtime' => strtotime($params['sendtime']), 'updatetime' => time(), 'message_type' => $params['message_type'], 'title' => $params['title'], ]; if (!$params['message_type']) { // 图文 $customData['message_json'] = $params['message_json']; $aMessageJson = json_decode($customData['message_json'], true); # 这里的bookIds 可能为空 $bookIds = array_column($aMessageJson, 'book_id'); $msgType = Message::MESSAGE_TYPE_IMAGE_TEXT; $aMessageJson = json_encode($aMessageJson); } else { $customData['message_text'] = $params['message_text']; $aMessageJson = json_decode($customData['message_text'], true); # 这里的bookIds 可能为空 $bookIds = array_column($aMessageJson, 'book_id'); $msgType = Message::MESSAGE_TYPE_LINK; $aMessageJson = json_encode($aMessageJson); } #4. 更新 custom_url表中的数据 $aMessageJson = json_decode(CustomService::instance()->processUrlForChannelId($officialAccountId, $aMessageJson), true); $this->customUrlModel->where('custom_id', 'eq', $ids)->delete(); CustomService::instance()->createCustomUrl( $bookIds, $ids, $customMediaPushId, $msgType, $officialAccountId, $official_account_type, $aMessageJson, $params['sendtime'] ); $result = $customService->updateCustomMessage($customData, $ids, $params['admin_id']); #endregion 更改客服消息 //$result = $row->allowField(true)->save($params); if ($result !== false) { $this->success(); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } if (!empty($row['message_json'])) { $row['message_json'] = UrlService::instance()->replaceReferralHost($this->auth->id, $row['message_json'], false)->data; } if (!empty($row['message_text'])) { $row['message_text'] = UrlService::instance()->replaceReferralHost($this->auth->id, $row['message_text'], false)->data; } $customService = new CustomService(); $customMediaInfo = $customService->getCustomMessageByPushId($row['custom_media_push_id']); $this->assign("customMediaInfo", $customMediaInfo); $this->assign("canedit", $canEdit); $this->view->assign("row", $row); $json = json_decode($row['user_json'], true); $from = $to = ''; if ($json['all'] == 0 && !$json['subscribe_time'] && $json['subscribe_range']) { list($from, $to) = explode('-', $json['subscribe_range']); if($from == 'NaN'){ $from = ''; } if($to == 'NaN'){ $to = ''; } if($from){ $from = date('Y-m-d H:i:s', $from); } if($to){ $to = date('Y-m-d H:i:s', $to); } } $this->view->assign('from', $from); $this->view->assign('to', $to); return $this->view->fetch(); } // 编辑图文次条 public function editImageText() { $channelId = $this->auth->id; if ($this->request->isPost()) { $params = $this->request->post(); $type = $params['row']['imgtxt_type']; $result = ['type' => $type]; if ($type == Message::MESSAGE_LINK_TYPE_BOOK) { $result = array_merge($result, $params['book']); #$result['book_name'] = $params['book_book_id_text']; } elseif ($type == Message::MESSAGE_LINK_TYPE_ACTIVITY) { $result = array_merge($result, $params['activity']); } elseif ($type == Message::MESSAGE_LINK_TYPE_RECENT) { $result = array_merge($result, $params['recent']); } elseif ($type == Message::MESSAGE_LINK_TYPE_MENU) { $result = array_merge($result, $params['menu']); } elseif ($type == Message::MESSAGE_LINK_TYPE_NOURL) { $result = array_merge($result, $params['no_url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_URL) { $result = array_merge($result, $params['url']); }elseif ($type == Message::MESSAGE_LINK_TYPE_DAILY_LINK) { $result = array_merge($result, $params['daily_url']); }if ($type == Message::MESSAGE_LINK_TYPE_MINI){ $params['mini']['title'] = $params['mini']['title'] ?? '小程序码'; $params['mini']['image'] = $params['mini']['image'] ?? ''; $result = array_merge($result,$params['mini']); $result['url'] = $params['mini']['image']; if ($result['mini_type'] == 3 && empty($result['url'])){ $this->error('图片必须上传'); } } $this->success('', null, $result); } else { $_params = $this->request->get(); $params = []; if (!empty($_params['media_id'])) { //$media_id = $this->request->get('media_id'); $media_id = $_params['media_id']; $media_data = $this->customMediaModel->get(['id' => $media_id]); $json_str = $media_data->message_json; $json_data = json_decode($json_str, true, 512, JSON_BIGINT_AS_STRING); if ($json_data) { $params = array_pop($json_data); } } else { $json_str = $_params['json']; $params = json_decode($json_str, true, 512, JSON_BIGINT_AS_STRING); } $params['page'] = $params['page']?? ''; $params['mini_type'] = $params['mini_type'] ?? 3; $referralModel = model('Referral'); $wxTypeList = $referralModel->getWxTypeList(); $pushList = $referralModel->getPushList(); $recentUrl = Message::getRecentFullPath($channelId); $aActivity = CommonService::instance()->getValidActivities($this->auth->id); $menuList = []; foreach (Menu::$allLinks as $key => $link) { $menuList[$key] = $link['title']; } if (array_key_exists('book_id', $params)) { $oBook = $this->bookModel->where(['id' => $params['book_id']])->find(); $this->assign('sex_text', $oBook->sex_text); } //获取独家书籍id $bnotin= []; ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$bnotin); $this->assignconfig('bnotin', $bnotin); //常用链接地址列表 $dailyLink = $this->getCurrentUserDailyLink(); $this->view->assign("dailyLink", $dailyLink); $this->assign('acc_type', Message::MESSAGE_TYPE_IMAGE_TEXT); $this->view->assign("params", $params); $this->view->assign("type", $params['type']); $this->view->assign("menuList", $menuList); $this->view->assign("wxTypeList", $wxTypeList); $this->view->assign("activityList", $aActivity); $this->view->assign("pushList", $pushList); $this->view->assign("recent_url", $recentUrl); } return $this->view->fetch(); } public function editlinktext() { $channelId = $this->auth->id; if ($this->request->isPost()) { $params = $this->request->post(); $params['push'] = '0'; $type = $params['row']['imgtxt_type']; $result = ['type' => $type]; if ($type == Message::MESSAGE_LINK_TYPE_BOOK) { $result = array_merge($result, $params['book']); #$result['book_name'] = $params['book_book_id_text']; } elseif ($type == Message::MESSAGE_LINK_TYPE_ACTIVITY) { $result = array_merge($result, $params['activity']); } elseif ($type == Message::MESSAGE_LINK_TYPE_RECENT) { $result = array_merge($result, $params['recent']); } elseif ($type == Message::MESSAGE_LINK_TYPE_MENU) { $result = array_merge($result, $params['menu']); } elseif ($type == Message::MESSAGE_LINK_TYPE_NOURL) { $result = array_merge($result, $params['no_url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_URL) { $result = array_merge($result, $params['url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_SIGN) { $params['sign']['url'] = "weixin://bizmsgmenu?msgmenucontent=" . Message::MESSAGE_KEYWORD . "&msgmenuid=" . time(); $result = array_merge($result, $params['sign']); }elseif ($type == Message::MESSAGE_LINK_TYPE_DAILY_LINK) { $result = array_merge($result, $params['daily_url']); } elseif ($type == Message::MESSAGE_LINK_TYPE_MINI){ $result = array_merge($result,$params['mini']); } $this->success('', null, $result); } else { $json_str = $this->request->get('json'); $params = json_decode($json_str, true, 512, JSON_BIGINT_AS_STRING); $params['page'] = $params['page']?? ''; $referralModel = model('Referral'); $wxTypeList = $referralModel->getWxTypeList(); $pushList = $referralModel->getPushList(); $recentUrl = getCurrentDomain($channelId, '/index/user/recent'); $aActivity = CommonService::instance()->getValidActivities($this->auth->id); $menuList = []; foreach (Menu::$allLinks as $key => $link) { $menuList[$key] = $link['title']; } if (array_key_exists('book_id', $params)) { $oBook = $this->bookModel->where(['id' => $params['book_id']])->find(); $this->assign('sex_text', $oBook->sex_text); } //常用链接地址列表 $dailyLink = $this->getCurrentUserDailyLink(); $this->view->assign("dailyLink", $dailyLink); //获取独家书籍id $bnotin= []; ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$bnotin); $this->assignconfig('bnotin', $bnotin); $this->assign('acc_type', Message::MESSAGE_TYPE_LINK); $this->view->assign("params", $params); $this->view->assign("type", $params['type']); $this->view->assign("menuList", $menuList); $this->view->assign("wxTypeList", $wxTypeList); $this->view->assign("activityList", $aActivity); $this->view->assign("pushList", $pushList); $this->view->assign("recent_url", $recentUrl); } return $this->view->fetch(); } public function messageJson($content, $resolve = true) { $channelId = $this->getCurrentAccountChannelId(); $contentData = json_decode($content, true)[0]; $url = $contentData['url']; $transferResult = UrlService::instance()->replaceReferralHost($channelId, $url, $resolve); $transferUrl = $transferResult->data; $contentData['url'] = $transferUrl; return json_encode([$contentData], JSON_UNESCAPED_UNICODE); } /** * 编辑 */ public function editold($ids = null) { $canEdit = 0; $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($row['sendtime'] <= time()) { //已发送,不能修改 $canEdit = 1; } if ($row['sendtime'] > time() && $row['sendtime'] - time() <= 600) { //发送前10分钟内不能修改 $canEdit = 1; } // 占位符 返解析为域名 $row['message_json'] = UrlService::instance()->replaceReferralHost($this->getCurrentAccountChannelId(), $row['message_json'], false)->data; if ($this->request->isPost()) { $this->error("新版客服消息上线后,老数据无法编辑"); } $this->assign("canedit", $canEdit); $this->view->assign("row", $row); return $this->view->fetch(); } /** * 获取当前用户可用的链接地址 * @return array */ protected function getCurrentUserDailyLink() { //常用链接地址 $dailyLink = CommonService::instance()->getTmpDailyLink(); $channelId = null; if ($this->auth->agent_id) { //配号代理商 $channelId = $this->auth->agent_id; } elseif ($this->group == 4) { //代理商 $channelId = $this->auth->channel_id; } elseif ($this->group == 3) { //渠道商 $channelId = $this->auth->channel_id; } if($channelId){ $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channelId); if (!($adminConfig['vip_state'] ?? false) && ($adminConfig['vip_goods_id'] ?? null)){ unset($dailyLink['vip']); } $configChannelIds = Config::get('site.smallpay_channel_id') ?? ''; if ($configChannelIds == '*') { $open = true; } else { $list = explode(',', $configChannelIds); $open = in_array($channelId, $list); } if ($open) { $adminConfig['small_goods_id'] = Config::get('site.smallpay_goods_id'); } if(!($adminConfig['small_goods_id'] ?? null)){ unset($dailyLink['smallpay']); } } return $dailyLink; } }