123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\cms\controller;
-
- use addons\cms\library\Service;
- use app\cms\model\Cms as CmsModel;
- use app\cms\model\CmsContent as CmsContentModel;
- use app\cms\model\Order as OrderModel;
- use think\Db;
-
- class Content extends Cmsbase
- {
- protected function initialize()
- {
- parent::initialize();
- $this->CmsModel = new CmsModel;
- }
-
- public function publish()
- {
- $groupinfo = $this->_check_group_auth($this->auth->groupid);
-
- if ($this->cmsConfig['web_contribute_verify'] && (!$this->auth->ischeck_email && !$this->auth->ischeck_mobile)) {
- $this->error("投稿必须激活邮箱或手机!");
- }
-
- $allowpostnum = CmsContentModel::where('uid', $this->auth->id)->whereTime('create_time', 'd')->count();
- if ($groupinfo['allowpostnum'] > 0 && $allowpostnum >= $groupinfo['allowpostnum']) {
- $this->error("今日投稿数量已达上限!");
- }
- if ($this->request->isPost()) {
- $data = $this->request->param('', '', 'trim,xss_clean');
-
- $rule = [
- 'modelField.title|标题' => 'require|length:3,100',
- 'modelField.catid|栏目' => 'require|integer',
- '__token__' => 'require|token',
- ];
- $result = $this->validate($data, $rule);
- if (true !== $result) {
- $this->error($result, null, ['token' => $this->request->token()]);
- }
- $catid = intval($data['modelField']['catid']);
- if (empty($catid)) {
- $this->error("请指定栏目ID!", null, ['token' => $this->request->token()]);
- }
- $catidPrv = Db::name('category_priv')->where(["catid" => $catid, "roleid" => $this->auth->groupid, "is_admin" => 0, "action" => "add"])->find();
- if (empty($catidPrv)) {
- $this->error("您没有该栏目投稿权限!", null, ['token' => $this->request->token()]);
- }
- $category = Db::name('Category')->find($catid);
- if (empty($category)) {
- $this->error('该栏目不存在!', null, ['token' => $this->request->token()]);
- }
- $fields = Db::name('model_field')->where('modelid', $category['modelid'])->where('isadd', 1)->column('name,ifsystem');
- $_data = [];
- foreach ($fields as $k => $v) {
- if (1 == $v && isset($data['modelField'][$k])) {
- $_data['modelField'][$k] = $data['modelField'][$k];
- } elseif (0 == $v && isset($data['modelFieldExt'][$k])) {
- $_data['modelFieldExt'][$k] = $data['modelFieldExt'][$k];
- }
- }
- $_data['modelField']['uid'] = $this->auth->id;
- $_data['modelField']['username'] = $this->auth->username;
-
-
- if ($groupinfo['allowpostverify']) {
- $_data['modelField']['status'] = 1;
- } else {
- $_data['modelField']['status'] = 0;
- }
- $id = 0;
- if ($category['type'] == 2) {
- $_data['modelFieldExt'] = isset($_data['modelFieldExt']) ? $_data['modelFieldExt'] : [];
- try {
- $id = $this->CmsModel->addModelData($_data['modelField'], $_data['modelFieldExt']);
- } catch (\Exception $ex) {
- $this->error($ex->getMessage(), null, ['token' => $this->request->token()]);
- }
- }
-
- if ($id) {
- CmsContentModel::create([
- 'catid' => $catid,
- 'content_id' => $id,
- 'uid' => $_data['modelField']['uid'],
- 'username' => $_data['modelField']['username'],
- 'create_time' => time(),
- 'status' => $_data['modelField']['status'],
- ]);
- }
- if ($_data['modelField']['status'] == 1) {
- $this->success('操作成功,内容已通过审核!', url('published'));
- } else {
- $this->success('操作成功,等待管理员审核!', url('published'));
- }
- } else {
- $step = $this->request->param('step/d', 1);
- if ($step == 1) {
- return $this->fetch('/content_declaration');
- }
- $catid = $this->request->param('catid/d', 0);
- $tree = new \util\Tree();
- $str = "<option value=@catidurl @selected @disabled>@spacer @catname</option>";
- $array = Db::name('Category')->order('listorder DESC, id DESC')->column('*', 'id');
- foreach ($array as $k => $v) {
- if ($v['id'] == $catid) {
- $array[$k]['selected'] = "selected";
- }
-
- if ($v['child'] == 1 || $v['type'] == 1) {
- $array[$k]['disabled'] = "disabled";
- $array[$k]['catidurl'] = url('publish', ['step' => 2]);
- } else {
- $array[$k]['disabled'] = "";
- $array[$k]['catidurl'] = url('publish', ['step' => 2, 'catid' => $v['id']]);
- }
- }
- $tree->init($array);
- $categoryselect = $tree->getTree(0, $str);
-
- if ($catid) {
- $category = Db::name('Category')->find($catid);
- if (empty($category)) {
- $this->error('该栏目不存在!');
- }
- if ($category['type'] == 2) {
- $modelid = $category['modelid'];
- $fieldList = Service::getFieldList($modelid);
- $this->assign([
- 'catid' => $catid,
- 'fieldList' => $fieldList,
- ]);
- }
- }
- $this->assign("categoryselect", $categoryselect);
- return $this->fetch('/content_publish');
- }
- }
-
-
-
- public function edit()
- {
- $groupinfo = $this->_check_group_auth($this->auth->groupid);
- if ($this->request->isPost()) {
- $data = $this->request->param('', '', 'trim,xss_clean');
-
- $rule = [
- 'modelField.title|标题' => 'require|length:3,100',
- 'modelField.catid|栏目' => 'require|integer',
- '__token__' => 'require|token',
- ];
- $result = $this->validate($data, $rule);
- if (true !== $result) {
- $this->error($result, null, ['token' => $this->request->token()]);
- }
- $id = intval($data['modelField']['id']);
- $catid = intval($data['modelField']['catid']);
- if (empty($id) || empty($catid)) {
- $this->error("请指定栏目ID!");
- }
- $category = Db::name('Category')->find($catid);
- if (empty($category)) {
- $this->error('该栏目不存在!');
- }
- $catidPrv = Db::name('category_priv')->where(["catid" => $catid, "roleid" => $this->auth->groupid, "is_admin" => 0, "action" => "add"])->find();
- if (empty($catidPrv)) {
- $this->error("您没有该栏目投稿权限!");
- }
- $fields = Db::name('model_field')->where('modelid', $category['modelid'])->where('isadd', 1)->column('name,ifsystem');
- $_data = [];
- foreach ($fields as $k => $v) {
- if (1 == $v && isset($data['modelField'][$k])) {
- $_data['modelField'][$k] = $data['modelField'][$k];
- } elseif (0 == $v && isset($data['modelFieldExt'][$k])) {
- $_data['modelFieldExt'][$k] = $data['modelFieldExt'][$k];
- }
- }
-
- if ($groupinfo['allowpostverify']) {
- $_data['modelField']['status'] = 1;
- } else {
- $_data['modelField']['status'] = 0;
- }
-
- if ($category['type'] == 2) {
- $_data['modelFieldExt'] = isset($_data['modelFieldExt']) ? $_data['modelFieldExt'] : [];
- try {
- $this->CmsModel->editModelData($_data['modelField'], $_data['modelFieldExt']);
- } catch (\Exception $ex) {
- $this->error($ex->getMessage());
- }
- }
- if ($_data['modelField']['status'] == 1) {
- CmsContentModel::where(['content_id' => $id, 'catid' => $catid])->update(['status' => 1]);
- $this->success('编辑成功,内容已通过审核!', url('published'));
- } else {
- CmsContentModel::where(['content_id' => $id, 'catid' => $catid])->update(['status' => 0]);
- $this->success('编辑成功,等待管理员审核!', url('published'));
- }
- } else {
- $id = $this->request->param('id/d', 0);
- $info = CmsContentModel::where(['uid' => $this->auth->id, 'id' => $id])->find();
- if (empty($info)) {
- $this->error('稿件不存在!');
- }
- $catid = $info['catid'];
-
- $category = getCategory($catid);
- if (empty($category)) {
- $this->error('该栏目不存在!', url('publish', ['step' => 2]));
- }
-
- $modelid = (int) $category['modelid'];
-
- if ($category['child'] || $category['type'] == 0) {
- $this->error("该栏目不允许投稿!", url('publish', ['step' => 2]));
- }
- $fieldList = Service::getFieldList($modelid, $info['content_id']);
- $this->assign([
- 'catid' => $catid,
- 'fieldList' => $fieldList,
- ]);
- return $this->fetch('/content_edit');
- }
-
- }
-
- public function published()
- {
- if ($this->request->isAjax()) {
- $limit = $this->request->param('limit/d', 10);
- $page = $this->request->param('page/d', 10);
- $type = $this->request->param('type/s', "");
- $where = ['uid' => $this->auth->id];
- if ('check' == $type) {
- $where['status'] = 1;
- }
- if ('checking' == $type) {
- $where['status'] = 0;
- }
- $total = CmsContentModel::where($where)->count();
- $_list = CmsContentModel::where($where)->page($page, $limit)->order(["id" => "DESC"])->select();
- foreach ($_list as $k => $v) {
- $modelid = getCategory($v['catid'], 'modelid');
- $tablename = ucwords(getModel($modelid, 'tablename'));
- $info = Db::name($tablename)->where(["id" => $v['content_id'], "sysadd" => 0])->find();
- if ($info) {
- $_list[$k]['url'] = buildContentUrl($v['catid'], $v['content_id'], $info['url']);
- $_list[$k]['title'] = $info['title'];
- $_list[$k]['catname'] = getCategory($v['catid'], 'catname');
- }
- }
- $result = ["code" => 0, "count" => $total, "data" => $_list];
-
- return json($result);
- }
- return $this->fetch('/content_published');
- }
-
-
- public function order()
- {
- if ($this->request->isAjax()) {
- $limit = $this->request->param('limit/d', 10);
- $page = $this->request->param('page/d', 1);
-
- $_list = OrderModel::where('user_id', $this->auth->id)->page($page, $limit)->order('id DESC')->select();
- $total = OrderModel::where('user_id', $this->auth->id)->count();
- $result = ["code" => 0, "count" => $total, "data" => $_list];
- return json($result);
-
- } else {
- return $this->fetch('/order_list');
- }
-
- }
-
-
- public function del()
- {
- $id = $this->request->param('id/d', 0);
- if (empty($id)) {
- $this->error('请指定需要删除的信息!');
- }
-
- $info = CmsContentModel::where('id', $id)->find();
-
- if ($info && $info['uid'] == $this->auth->id && $info['status'] != 1) {
-
- $category = getCategory($info['catid']);
- if (!$category) {
- $this->success('栏目不存在!');
- }
- try {
- $this->CmsModel->deleteModelData($category['modelid'], $info['content_id']);
- } catch (\Exception $ex) {
- $this->error($ex->getMessage());
- }
- $this->success('删除成功!');
- } else {
- $this->error('对不起,你无权删除!');
- }
- }
-
-
- private function _check_group_auth($groupid)
- {
- $grouplist = cache("Member_Group");
- if (!$grouplist[$groupid]['allowpost']) {
- $this->error('你没有权限投稿,请升级会员组!');
- }
- return $grouplist[$groupid];
- }
-
- }
|