public function add() { if (IS_POST) { $title = I('title', '', 'trim') or $this->error('请输入标题!'); $content = I('content', '', 'trim') or $this->error('请输入说明文字!'); $url = I('url', '', 'trim') or $this->error('请输入页面链接!'); $pusher = new \Common\Util\XgPush(); $limit_type = I('limit_type') or $this->error('请选择推送范围!'); in_array($limit_type, ['ALL', 'AND', 'OR', 'MOBILE', 'REG']) or $this->error('请选择正确的推送范围!'); if ($limit_type === 'ALL') { M('common_push')->add(['created' => time(), 'type' => 2, 'title' => $title, 'content' => $content, 'url' => $url, 'uid' => $this->_user['uid'], 'uname' => $this->_user['uname']]); $pusher->sendAll(['title' => $title, 'content' => $content, 'url' => $url]); } else { if ($limit_type === 'MOBILE') { $mobile = []; foreach (preg_split('/\\D/i', I('mobile')) as $vo) { if (!$vo) { continue; } preg_match('/\\d{11}/', $vo) or $this->error('手机号格式错误:' . $vo); $mobile[] = $vo; } $mobile or $this->error('请输入手机号!'); M('common_push')->add(['created' => time(), 'type' => 1, 'title' => $title, 'content' => $content, 'url' => $url, 'tag' => implode(',', $mobile), 'uid' => $this->_user['uid'], 'uname' => $this->_user['uname']]); $pusher->sendAccountList($mobile, ['title' => $title, 'content' => $content, 'url' => $url]); } else { if ($limit_type === 'REG') { $start = I('reg_start'); $end = I('reg_end'); $where = []; if ($start) { $where[] = ['egt', strtotime($start)]; } if ($end) { $where[] = ['elt', strtotime($end . ' 23:59:59')]; } $where = $where ? ['created' => $where] : []; M('user')->where($where)->count() <= 10000 or $this->error('暂只支持每次10000个用户发送,请缩小范围!'); $mobile = M('user')->where($where)->getField('mobile', true); $mobile or $this->error('此范围内无用户!'); debug($mobile); M('common_push')->add(['created' => time(), 'type' => 1, 'title' => $title, 'content' => $content, 'url' => $url, 'tag' => $start . ' - ' . $end, 'uid' => $this->_user['uid'], 'uname' => $this->_user['uname']]); $pusher->sendAccountList($mobile, ['title' => $title, 'content' => $content, 'url' => $url]); } else { // 组装标签 $tag = I('tag'); foreach (array_filter(I('android_version', [], 'trim')) as $vo) { $tag[] = 'platform_android_' . $vo; } foreach (array_filter(I('ios_version', [], 'trim')) as $vo) { $tag[] = 'platform_ios_' . $vo; } $tag or $this->error('请选择条件!'); M('common_push')->add(['created' => time(), 'type' => 3, 'title' => $title, 'content' => $content, 'url' => $url, 'tag' => implode(',', $tag), 'tag_op' => $limit_type, 'uid' => $this->_user['uid'], 'uname' => $this->_user['uname']]); $pusher->sendTag($tag, ['title' => $title, 'content' => $content, 'url' => $url], $limit_type); } } } $this->success('推送成功!', U('index')); exit; } // 获取所有学校信息 $university = M('university')->field('id,name')->where('status=1')->select(); // 获取所有校区信息 $campus = M('university_campus')->field('id,name,university_name')->where('status=1')->select(); // 获取所有入学年份 $start_year = M('user_info')->distinct(true)->field('start_year')->where('start_year>0')->order('start_year asc')->select(); $this->assign('meta_title', '新增推送'); $this->assign('_university', $university); $this->assign('_campus', $campus); $this->assign('_start_year', $start_year); $this->display(); }