123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- <?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\Common;
- use app\common\constants\ErrorCode;
- use app\common\constants\Menu;
- use app\common\constants\Message;
- use app\common\constants\OfficialAccount;
- use app\common\controller\Backend;
- use app\common\model\Book;
- use app\common\model\SubscriptionRelation;
- use app\common\model\VipAdminBind;
- use app\main\constants\AdminConstants;
- use app\main\service\MiniProgramService;
- /**
- * 客服图文消息素材库
- *
- * @icon fa fa-circle-o
- */
- class Vipimagetextmedia extends Backend{
- /**
- * @var \app\admin\model\CustomMedia
- */
- protected $model = null;
- /**
- * @var \app\common\model\VipAdminBind
- */
- protected $vipBindModel = null;
- /**
- * @var \app\common\model\AdminConfig
- */
- protected $adminConfigModel = null;
- /**
- * @var \app\common\model\SubscriptionRelation
- */
- protected $subscriptionRelationModel = null;
- /**
- * @var \app\admin\model\Custom
- */
- protected $customModel;
- /**
- * @var CustomService
- */
- protected $custom_service = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('CustomMedia');
- $this->custom_service = new CustomService();
- $this->vipBindModel = model('VipAdminBind');
- $this->adminConfigModel = model('AdminConfig');
- $this->subscriptionRelationModel = model('SubscriptionRelation');
- $this->customModel = model('Custom');
- $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()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $channelIds = $this->vipBindModel->getChannelIds($this->auth->id);
- $channelIds[] = $this->auth->id;
- $condition = [
- 'message_type' => Message::MESSAGE_TYPE_IMAGE_TEXT,
- 'status' => Common::STATUS_NORMAL,
- ];
- $condition['created_admin_id'] = ['in', $channelIds];
- $filter = $this->request->get("filter", '');
- $filter = json_decode($filter, true);
- $where = [];
- if ($filter) {
- foreach ($filter as $k => $v) {
- switch ($k) {
- case 'id':
- $where[$k] = $v;
- break;
- case 'message_json[*].book_name':
- $where["message_json->'$[*].book_name'"] = ['like', "%$v%"];
- break;
- default:
- break;
- }
- }
- }
- $total = $this->model
- ->where($where)
- ->where($condition)
- ->count();
- $list = $this->model
- ->where($where)
- ->where($condition)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 图文客服消息素材库 群发消息
- * @param string $ids
- * @param string $official_type 0 =>群发服务号 1=>群发订阅号
- */
- public function multiSendMessage($ids = '', $official_type = 0)
- {
- if ($ids) {
- if ($this->request->isPost()) {
- $params = $this->request->param();
- $sendTime = $params['row']['sendtime'];
- $iAdminId = $this->auth->id;
- if ($official_type == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE) {
- if ($params['row']['select_type'] == 1) {
- //分组 拉取公众号ID
- $groupIds = trim($params['row']['group_id'], ',');
- $channelRows = model("VipGroupInfo")->where('group_id', 'in', $groupIds)->field("channel_id")->select();
- $channelIds = array_unique(array_column($channelRows, 'channel_id'));
- } else {
- $channelIds = $params['row']['service_id'];
- }
- $result = CustomService::instance()->multiSendMessageService($ids, $sendTime, $channelIds, $iAdminId, ['group_id' => $params['row']['group_id'], 'select_type' => $params['row']['select_type']]);
- } else {
- $subIds = $params['row']['sub_id'];
- $channelId = $params['row']['channel_id'];
- $result = CustomService::instance()->multiSendMessageSub($ids, $sendTime, $subIds, $channelId, $iAdminId);
- }
- if ($result['error'] == ErrorCode::SUCCESS) {
- $this->success();
- } else {
- $this->error($result['msg']);
- }
- } else {
- $vipId = $this->auth->id;
- $adminIds = $this->vipBindModel->getChannelIds($vipId);
- if ($official_type == OfficialAccount::OFFICIAL_ACCOUNT_TYPE_SERVICE) {//公众号
- $accList = $this->adminConfigModel->getListByAcc($adminIds);
- $this->assign("acclist", $accList);
- } elseif ($official_type == 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']);
- $this->assign('acc_type', $official_type);
- return $this->fetch();
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- /**
- * 查看详情
- * @param string $ids
- */
- public function checkDetails($ids = ''){
- if($ids){
- $this->success('Ok');
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- /**
- * 查看消息详情
- * @param string $id
- */
- public function viewDetail($ids = '')
- {
- if($ids) {
- if ($this->request->isAjax()) {
- $result = CustomService::instance()->getCustomMediaDetail($ids);
- return json($result);
- }
- return $this->fetch();
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- /**
- * 编辑标题
- * @param string $ids
- */
- public function editTitle($ids = '', $index = 0, $title){
- if($ids && $title){
- $media = $this->model->get(['id'=>$ids]);
- $message_json = json_decode($media->message_json);
- $message_obj = $message_json[$index];
- $message_obj->title = $title;
- $message_json[$index] = $message_obj;
- $rst = $this->model->save(['message_json' => json_encode($message_json)], ['id'=>$ids]);
- if($rst){
- return json(['code'=>0, 'msg'=>'修改成功', 'data'=>$title]);
- }else{
- return json(['code'=>1, 'msg'=>'修改失敗']);
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids 和 title'));
- }
- /**
- * 编辑封面
- * @param string $ids
- */
- public function editCover($ids = '', $index = 0, $cover = ''){
- if($ids && $cover){
- $media = $this->model->get(['id'=>$ids]);
- $message_json = json_decode($media->message_json);
- $message_obj = $message_json[$index];
- $message_obj->image = $cover;
- $message_json[$index] = $message_obj;
- $rst = $this->model->save(['message_json' => json_encode($message_json)], ['id'=>$ids]);
- if($rst){
- return json(['code'=>0, 'msg'=>'修改成功', 'data'=>$cover]);
- }else{
- return json(['code'=>1, 'msg'=>'修改失敗']);
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids 和 cover'));
- }
- // 编辑图文次条
- 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_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 {
- // 获取编辑时,传入的参数
- $json_str = $this->request->get('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);
- $customActivity = CommonService::instance()->getVipActivityList($this->auth->id);
- $menuList = [];
- foreach (Menu::$allLinks as $key => $link) {
- $menuList[$key] = $link['title'];
- }
- if(array_key_exists('book_id', $params)){
- $mBook = new Book();
- $oBook = $mBook->where(['id'=>$params['book_id']])->find();
- $this->assign('sex_text', $oBook->sex_text);
- }
- $bnotin= [];
- ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$bnotin);
- $this->assignconfig('bnotin', $bnotin);
- //常用链接地址列表
- $dailyLink = CommonService::instance()->getTmpDailyLink();
- $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("customActivityList", $customActivity);
- $this->view->assign("pushList", $pushList);
- $this->view->assign("dailyLink", $dailyLink);
- //$this->view->assign("recent_url", $recentUrl);
- }
- return $this->view->fetch();
- }
- /**
- * 获取素材 message
- * @param string $ids
- */
- public function getMediaMessage($ids = '', $index = 0)
- {
- $media = $this->model->get(['id' => $ids]);
- $message_json_arr = json_decode($media->message_json, true);
- //兼容description
- if (!isset($message_json_arr[$index]['description'])) {
- $message_json_arr[$index]['description'] = '';
- }
- $data = json_encode($message_json_arr[$index]);
- if ($media->message_json) {
- return json(['code'=> 0, 'msg'=>'success', 'data'=> $data]);
- } else {
- return json(['code'=> 1, 'msg'=>'fail', 'data'=> '']);
- }
- }
- /**
- * 编辑链接
- * @param string $ids
- */
- public function editLink($index = 0, $ids = '', $message_json = '')
- {
- if ($ids && $message_json) {
- $media = $this->model->get(['id'=>$ids]);
- $media_arr = json_decode($media ->message_json, true);
- # 替换值
- $media_arr[$index] = json_decode($message_json, true);
- $rst = $this->model->save(['message_json' => json_encode($media_arr)], ['id'=>$ids]);
- if($rst){
- return json(['code'=>0, 'msg'=>'修改成功']);
- }else{
- return json(['code'=>1, 'msg'=>'修改失敗']);
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids 和 message_json'));
- }
- public function del($ids = ''){
- if ($ids) {
- $pk = $this->model->getPk();
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- foreach ($list as $k => $v) {
- #$count += $v->delete();
- $count += $v->deleteMedia($v->id);
- }
- if ($count) {
- $this->success();
- }else {
- $this->error(__('No rows were deleted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- }
|