model = model('Custom'); $this->vipAdminBindModel = model('VipAdminBind'); $this->adminConfigModel = model('AdminConfig'); $this->subscriptionRelationModel = model('SubscriptionRelation'); $this->customMediaPushModel = model('CustomMediaPush'); $this->customUrlModel = model('CustomUrl'); $miniOpen = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group); $miniPages = MiniProgramService::instance()->getMiniPage(); $this->assign('miniOpen',$miniOpen); $this->assign('miniPages',$miniPages); } /** * 测试发送客服消息 * @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, $is_group = 0, $group_id = '' ) { 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 { $params = $this->request->post(); if ($params['is_group'] == 1) { $groupIds = trim($params['group_id'], ','); $channelRows = model("VipGroupInfo")->where('group_id', 'in', $groupIds)->field("channel_id")->select(); $admin_id = array_unique(array_column($channelRows, 'channel_id')); } $result = CustomService::instance()->sendMessageServiceToUser((array)$admin_id, $user_id, $cdata, $ids, $msg_type); } return json($result); } public function addimagetext() { $vipId = $this->auth->id; //$officialAccountType = $this->request->get("acc_type"); $officialAccountType = OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE; /*if ($officialAccountType == null || !in_array($officialAccountType, OfficialAccount::officialAccountTypes)) { return $this->view->fetch("addimagetextindex"); }*/ if ($this->request->isPost()) { $params = $this->request->post("row/a"); if(isset($params['sub_from'])){ unset($params['sub_from']); } if(isset($params['sub_to'])){ unset($params['sub_to']); } $msgContent = !empty($params['message_json']) ? $params['message_json'] : json_encode(array()); $sendTime = $params['sendtime']; $iAdminId = $this->auth->id; if ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE) {//公众号 $channelIds = $params['service_id'] ?? []; if ($params['select_type'] == 1) { //分组 拉取公众号ID $groupIds = trim($params['group_id'], ','); $channelRows = model("VipGroupInfo")->where('group_id', 'in', $groupIds)->field("channel_id")->select(); $channelIds = array_unique(array_column($channelRows, 'channel_id')); } CustomService::instance()->createPushService($sendTime, $channelIds, $iAdminId, Message::MESSAGE_TYPE_IMAGE_TEXT, $msgContent, 0, $params['is_save_media'], '', $params['user_json'], Custom::CUSTOM_CREATED_FROM_GROUP_SEND, ['group_id' => $params['group_id'], 'select_type' => $params['select_type']]); } elseif ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SUBSCRIPTION) {//订阅号 $subIds = $params['sub_id']; $channelId = $params['channel_id']; CustomService::instance()->createPushSub($sendTime, $subIds, $channelId, $iAdminId, Message::MESSAGE_TYPE_IMAGE_TEXT, $msgContent, 0, $params['is_save_media'], Custom::CUSTOM_CREATED_FROM_GROUP_SEND); } if ($params['is_save_media']) { $jumpUrl = '/admin/vipcustom/vipimagetextmedia/index?ref=addtabs'; } else { $jumpUrl = '/admin/vipcustom/vipimagetextmediapush/index?ref=addtabs'; } $this->success('操作成功', null, ['jump' => $jumpUrl]); } else { $this->assign("acc_type", $officialAccountType); $adminIds = $this->vipAdminBindModel->getChannelIds($vipId); if ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE) {//公众号 $accList = $this->adminConfigModel->getListByAcc($adminIds); $this->assign("acclist", $accList); } elseif ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SUBSCRIPTION) {//订阅号 $adminIds[] = $vipId; $subList = $this->subscriptionRelationModel->getSubListByAdminId($adminIds); $this->assign("sublist", $subList); } $wechatAccountLimit = CommonService::instance()->getWechatAccountLimit(); $this->assign('sub_limited', $wechatAccountLimit['subLimitNum']); $this->assign('service_limited', $wechatAccountLimit['serLimitNum']); return $this->view->fetch(); } } public function addlinktext() { $vipId = $this->auth->id; //$officialAccountType = $this->request->get("acc_type"); $officialAccountType = OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE; /*if ($officialAccountType == null || !in_array($officialAccountType, OfficialAccount::officialAccountTypes)) { return $this->view->fetch("addlinktextindex"); }*/ if ($this->request->isPost()) { $params = $this->request->post("row/a"); if(isset($params['sub_from'])){ unset($params['sub_from']); } if(isset($params['sub_to'])){ unset($params['sub_to']); } $msgContent = !empty($params['message_text']) ? $params['message_text'] : ''; $sendTime = $params['sendtime']; $iAdminId = $this->auth->id; if ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE) {//公众号 $channelIds = $params['service_id'] ?? []; if ($params['select_type'] == 1) { //分组 拉取公众号ID $groupIds = trim($params['group_id'], ','); $channelRows = model("VipGroupInfo")->where('group_id', 'in', $groupIds)->field("channel_id")->select(); $channelIds = array_unique(array_column($channelRows, 'channel_id')); } CustomService::instance()->createPushService($sendTime, $channelIds, $iAdminId, Message::MESSAGE_TYPE_LINK, $msgContent, 0, $params['is_save_media'], '', $params['user_json'] ?? '', Custom::CUSTOM_CREATED_FROM_GROUP_SEND, ['group_id' => $params['group_id'], 'select_type' => $params['select_type']]); } elseif ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SUBSCRIPTION) {//订阅号 $subIds = $params['sub_id']; $channelId = $params['channel_id']; CustomService::instance()->createPushSub($sendTime, $subIds, $channelId, $iAdminId, Message::MESSAGE_TYPE_LINK, $msgContent, 0, $params['is_save_media'], Custom::CUSTOM_CREATED_FROM_GROUP_SEND); } if ($params['is_save_media']) { $jumpUrl = '/admin/vipcustom/viplinktextmedia/index?ref=addtabs'; } else { $jumpUrl = '/admin/vipcustom/viplinktextmediapush/index?ref=addtabs'; } $this->success('操作成功', null, ['jump' => $jumpUrl]); } else { $this->assign("acc_type", $officialAccountType); $adminIds = $this->vipAdminBindModel->getChannelIds($vipId); if ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE) {//公众号 $accList = $this->adminConfigModel->getListByAcc($adminIds); $this->assign("acclist", $accList); } elseif ($officialAccountType == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SUBSCRIPTION) {//订阅号 $adminIds[] = $vipId; $subList = $this->subscriptionRelationModel->getSubListByAdminId($adminIds); $this->assign("sublist", $subList); } $wechatAccountLimit = CommonService::instance()->getWechatAccountLimit(); $this->assign('sub_limited', $wechatAccountLimit['subLimitNum']); $this->assign('service_limited', $wechatAccountLimit['serLimitNum']); return $this->view->fetch(); } } /** * 添加消息 */ public function createmessage() { $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']); } 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_CUSTOMIZE_ACTIVITY) { $result = array_merge($result, $params['customize_activity']); }elseif ($type == Message::MESSAGE_LINK_TYPE_DAILY_LINK) { $result = array_merge($result, $params['daily_url']); }elseif ($type == Message::MESSAGE_LINK_TYPE_MINI){ if ($params['mini'] && $params['mini']['mini_type'] ==4){ $params['mini']['title'] = !empty($params['mini']['title']) ? $params['mini']['title'] : '小程序码'; } $result = array_merge($result,$params['mini']); } $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); $customActivity = CommonService::instance()->getVipActivityList($this->auth->id); $menuList = []; foreach (Menu::$allLinks as $key => $link) { $menuList[$key] = $link['title']; } //常用链接地址列表 $dailyLink = CommonService::instance()->getTmpDailyLink(); $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("customActivityList", $customActivity); $this->view->assign("pushList", $pushList); //$this->view->assign("recent_url", $recentUrl); } return $this->view->fetch(); } /** * 添加次条 * @return string * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function createlinkmessage() { $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_CUSTOMIZE_ACTIVITY) { $result = array_merge($result, $params['customize_activity']); } 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(); $adminIds = $this->vipAdminBindModel->getChannelIds($channelId); $channelId = array_pop($adminIds); $recentUrl = getCurrentDomain($channelId, '/index/user/recent'); $aActivity = CommonService::instance()->getValidActivities($this->auth->id); $customActivity = CommonService::instance()->getVipActivityList($this->auth->id); $menuList = []; foreach (Menu::$allLinks as $key => $link) { $menuList[$key] = $link['title']; } //常用链接地址列表 $dailyLink = CommonService::instance()->getTmpDailyLink(); $this->view->assign("dailyLink", $dailyLink); $this->assign('acc_type', Message::MESSAGE_TYPE_LINK); $this->view->assign("customActivityList", $customActivity); $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(); } /** * * @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)]); } } /** * 获取公众号列表AJAX * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getServiceListAjax() { $acc_name = $this->request->param("acc_name") ?: ''; $adminIds = $this->vipAdminBindModel->getChannelIds($this->auth->id); $res = $this->adminConfigModel->getListByAcc($adminIds, $acc_name); return json(['list' => $res, 'total' => count($res)]); } }