/** * 公用入口文件 */ public function entrance() { $classId = intval(I('get.ctgClassID')); //获取栏目的国家id //模型-栏目数据 $modData = get_mod_data(); $gid_map = C('GID_CLASS_MAP'); $cityID = session('CityID'); $cityGid = get_city_gid(); $gid = $cityGid[$cityID]; if ($modData[$classId]['mark'] != $gid_map[$gid]) { $this->redirect('Home/Class/index'); } //获取文件夹名称 $tplInfo = M('CtgClass')->field('level,index_tpl,list_tpl')->where(array('ctgClassID' => $classId))->find(); if ($tplInfo['level'] == 1) { $this->index($classId); $this->theme('bootstrap')->display($tplInfo['index_tpl'] . '/index'); } else { $this->lists($classId); $this->theme('bootstrap')->display($tplInfo['list_tpl']); } }
/** * 处理发布内容 * @author liuxiaolin <*****@*****.**> * @return void */ public function postAction() { $uid = $_SESSION['userID']; //检测新注册用户 $checkUserInfo = $this->checkNewUserPost(); if ($checkUserInfo['status'] == false) { $this->ajaxReturn(['code' => -1, 'msg' => '新注册用户请在注册' . C('NEW_USER_POST_TIME') . '分钟后发帖'], 'json'); } $idList = array(9, 10, 11, 12); $userInfo = M('user')->field('groupID')->where("userID={$uid}")->find(); if (!in_array($userInfo['groupID'], $idList)) { //检测发贴是否超过限制 $check = $this->checkPostTimes(); if ($check['status'] == false) { $this->ajaxReturn(['code' => -1, 'msg' => '超过发贴限制~'], 'json'); } //检测发帖时间间隔 $message = $this->checkTimesInterval(); if ($message['status'] == false) { $this->ajaxReturn(['code' => -1, 'msg' => '发帖时间间隔为' . C('INTERVAL_TIME') . '分钟'], 'json'); } } $groupID = M('user')->where(array('userID' => $uid))->getField('groupID'); if ($groupID == 4) { $this->ajaxReturn(['code' => -1, 'msg' => '你已被加入黑名单,不允许发布'], 'json'); } $post = I('post.post'); //存入ybirds_ctg_data表的原始数据 $postdb = I('post.postdb'); //存入ybirds_ctg_dataXX表的原始数据 $token = I('post.token'); //去除空白字符 trim_all($post); trim_all($postdb); //初始化错误提示信息 $errorMsg = ''; //传入的数据验证处理 //if (!empty($post['qq'])) { // if (!preg_match('/^\d{5,12}$/', $post['qq'])) { // $errorMsg .= 'qq号不符合规则'; // } //} //if (!empty($post['email'])) { // if (!preg_match('/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/', $post['email'])) { // $errorMsg .= '电子邮件不符合规则'; // } //} if (empty($post['title'])) { $errorMsg .= '标题必须填写'; } if (empty($postdb['content_txt'])) { $errorMsg .= '详细内容必须填写'; } //if (empty($post['address'])) { // $errorMsg .= '联系地址必须填写'; //} //if (empty($post['telephone'])) { // $errorMsg .= '联系电话须填写'; //} //如果有验证不通过,则返回code为-1 if (!empty($errorMsg)) { $resData = ['code' => -1, 'msg' => $errorMsg]; $this->ajaxReturn($resData, "json"); } //处理$postdb数据, 如果是数组,则转换成字符串 foreach ($postdb as $key => $value) { if (is_array($value)) { $postdb[$key] = implode(',', $value); } } //防止重复担提交 if ($token != session('token')) { $resData = ['code' => -1, 'msg' => '你已经提交过了,请不要重复提交']; $this->ajaxReturn($resData, "json"); } session('token', null); //处理token; $tokenArr = unserialize(authcode($token, 'DECODE', C('AUTH_TOKEN'))); if (!is_array($tokenArr)) { $resData = ['code' => -1, 'msg' => '令牌token出错,请刷新页面重试']; $this->ajaxReturn($resData, "json"); } //模型-栏目数据 $dataModel = M('ctgData'); $fdataModel = M('ctgData' . $tokenArr['mid']); //type=0表示新增,type=1表示编辑 if ($tokenArr['type'] == 0) { //处理$post数组, $post['userID'] = session('userID'); $post['userName'] = session('userName'); $post['ip'] = get_client_ip(); $post['postTime'] = time(); $post['editTime'] = time(); $post['editor'] = session('userName'); $cityGid = get_city_gid(); $post['gid'] = $cityGid[$post['cityID']]; $post['modID'] = $tokenArr['mid']; $post['ctgClassID'] = $tokenArr['ctgClassID']; //开启事务 $dataModel->startTrans(); $res1 = $dataModel->data($post)->add(); $postdb['dataID'] = $res1; $res2 = $fdataModel->data($postdb)->add(); if ($res1 !== FALSE && $res2 !== FALSE) { $dataModel->commit(); $trend['title'] = $post['title']; $trend['time'] = $post['postTime']; $trend['content'] = strip_tags($postdb['content_txt']); if (mb_strwidth($trend['content'], 'utf8') > 200) { $trend['content'] = mb_strimwidth($trend['content'], 0, 200, '......', 'utf8'); } $trend['dataID'] = $postdb['dataID']; genTrend($trend, 'cat'); $this->checkCredit('Class'); //发布分类积分处理 $resData = ['code' => 1, 'msg' => '发布成功']; //发布的数量加1 M('member')->where("uid={$_SESSION['userID']}")->setInc('ctgs'); } else { $dataModel->rollback(); $resData = ['code' => -1, 'msg' => '发布失败,请重试~']; } //编辑信息 } elseif ($tokenArr['type'] == 1) { $post['editTime'] = time(); $post['editor'] = session('?userName') ? session('userName') : session('adminUserName'); $post['dataID'] = $tokenArr['dataID']; //开启事务 $dataModel->startTrans(); $res1 = $dataModel->data($post)->save(); $res2 = $fdataModel->data($postdb)->where(['dataID' => $post['dataID']])->save(); if ($res1 !== FALSE && $res2 !== FALSE) { $dataModel->commit(); $resData = ['code' => 1, 'msg' => '编辑成功']; } else { $dataModel->rollback(); $resData = ['code' => -1, 'msg' => '编辑失败,请重试~']; } } M('postlog')->data(['days' => date('Ymd'), 'uid' => session('userID'), 'type' => 0])->add(); $this->ajaxReturn($resData, "json"); }