123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- <?php
- namespace app\admin\controller\vipcustom;
- use app\admin\service\AdminConfigService;
- use app\admin\service\CommonService;
- use app\admin\service\CustomService;
- use app\admin\service\ExclusiveService;
- use app\common\constants\Custom as constantCustom;
- use app\common\constants\Custom;
- use app\common\constants\Menu;
- use app\common\constants\Message;
- use app\common\constants\OfficialAccount;
- use app\common\controller\Backend;
- use app\common\constants\Common;
- use app\main\constants\AdminConstants;
- use app\main\constants\BookConstants;
- use app\main\service\MiniProgramService;
- use think\db\Query;
- class Createcustom extends Backend
- {
- /**
- * @var \app\admin\model\Custom
- */
- protected $model = null;
- /**
- * @var \app\common\model\VipAdminBind
- */
- protected $vipAdminBindModel = null;
- /**
- * @var \app\common\model\AdminConfig
- */
- protected $adminConfigModel = null;
- /**
- * @var \app\common\model\SubscriptionRelation
- */
- protected $subscriptionRelationModel = null;
- /**
- * @var \app\admin\model\CustomMediaPush
- */
- protected $customMediaPushModel = null;
- /**
- * @var \app\admin\model\CustomUrl
- */
- protected $customUrlModel = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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)]);
- }
- }
|