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')); } }