123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899 |
- <?php
- namespace app\admin\controller;
- use app\admin\service\CommonService;
- use app\admin\service\ExclusiveService;
- use app\common\model\Book;
- use app\admin\service\CustomService;
- use app\common\constants\Common;
- use app\common\constants\Menu;
- use app\common\constants\Message;
- use app\common\constants\OfficialAccount;
- use app\common\controller\Backend;
- use app\common\model\AdminConfig;
- use app\common\constants\Custom as CustomConstants;
- use app\common\library\WeChatObject;
- use app\main\constants\AdminConstants;
- use app\main\constants\BookConstants;
- use app\main\service\AdminService;
- use app\main\service\MiniProgramService;
- use app\main\service\UrlService;
- use think\Controller;
- use think\db\Query;
- use think\Log;
- use think\Request;
- use app\common\controller\Api;
- use think\Config;
- use think\Model;
- use EasyWeChat\Factory;
- use app\common\library\Redis;
- use EasyWeChat\Kernel\Messages\News;
- use EasyWeChat\Kernel\Messages\NewsItem;
- use Symfony\Component\Cache\Simple\RedisCache;
- /**
- * 客服消息管理
- *
- * @icon fa fa-circle-o
- */
- class Custom extends Backend
- {
- /**
- * @var \app\admin\model\Custom
- */
- protected $model = null;
- /**
- * @var AdminConfig
- */
- protected $adminConfigModel = null;
- /**
- * @var \app\admin\model\CustomMedia
- */
- protected $customMediaModel = null;
- /**
- * @var \app\admin\model\CustomMediaPush
- */
- protected $customMediaPushModel = null;
- /**
- * @var \app\admin\model\CustomUrl
- */
- protected $customUrlModel = null;
- /**
- * @var \app\common\model\Referral
- */
- protected $referralModel = null;
- /**
- * @var \app\common\model\Book
- */
- protected $bookModel = null;
- /**
- * 是否开启数据限制
- * 支持auth/personal
- * 表示按权限判断/仅限个人
- * 默认为禁用,若启用请务必保证表中存在admin_id字段
- */
- protected $dataLimit = 'personal';
- public function _initialize()
- {
- parent::_initialize();
- $this->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;
- }
- }
|