控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 会员投稿管理
  13. // +----------------------------------------------------------------------
  14. namespace app\cms\controller;
  15. use addons\cms\library\Service;
  16. use app\cms\model\Cms as CmsModel;
  17. use app\cms\model\CmsContent as CmsContentModel;
  18. use app\cms\model\Order as OrderModel;
  19. use think\Db;
  20. class Content extends Cmsbase
  21. {
  22. protected function initialize()
  23. {
  24. parent::initialize();
  25. $this->CmsModel = new CmsModel;
  26. }
  27. public function publish()
  28. {
  29. $groupinfo = $this->_check_group_auth($this->auth->groupid);
  30. //没有认证用户不得投稿
  31. if ($this->cmsConfig['web_contribute_verify'] && (!$this->auth->ischeck_email && !$this->auth->ischeck_mobile)) {
  32. $this->error("投稿必须激活邮箱或手机!");
  33. }
  34. //判断每日投稿数
  35. $allowpostnum = CmsContentModel::where('uid', $this->auth->id)->whereTime('create_time', 'd')->count();
  36. if ($groupinfo['allowpostnum'] > 0 && $allowpostnum >= $groupinfo['allowpostnum']) {
  37. $this->error("今日投稿数量已达上限!");
  38. }
  39. if ($this->request->isPost()) {
  40. $data = $this->request->param('', '', 'trim,xss_clean');
  41. // 验证数据
  42. $rule = [
  43. 'modelField.title|标题' => 'require|length:3,100',
  44. 'modelField.catid|栏目' => 'require|integer',
  45. '__token__' => 'require|token',
  46. ];
  47. $result = $this->validate($data, $rule);
  48. if (true !== $result) {
  49. $this->error($result, null, ['token' => $this->request->token()]);
  50. }
  51. $catid = intval($data['modelField']['catid']);
  52. if (empty($catid)) {
  53. $this->error("请指定栏目ID!", null, ['token' => $this->request->token()]);
  54. }
  55. $catidPrv = Db::name('category_priv')->where(["catid" => $catid, "roleid" => $this->auth->groupid, "is_admin" => 0, "action" => "add"])->find();
  56. if (empty($catidPrv)) {
  57. $this->error("您没有该栏目投稿权限!", null, ['token' => $this->request->token()]);
  58. }
  59. $category = Db::name('Category')->find($catid);
  60. if (empty($category)) {
  61. $this->error('该栏目不存在!', null, ['token' => $this->request->token()]);
  62. }
  63. $fields = Db::name('model_field')->where('modelid', $category['modelid'])->where('isadd', 1)->column('name,ifsystem');
  64. $_data = [];
  65. foreach ($fields as $k => $v) {
  66. if (1 == $v && isset($data['modelField'][$k])) {
  67. $_data['modelField'][$k] = $data['modelField'][$k];
  68. } elseif (0 == $v && isset($data['modelFieldExt'][$k])) {
  69. $_data['modelFieldExt'][$k] = $data['modelFieldExt'][$k];
  70. }
  71. }
  72. $_data['modelField']['uid'] = $this->auth->id;
  73. $_data['modelField']['username'] = $this->auth->username;
  74. //判断会员组投稿是否需要审核
  75. if ($groupinfo['allowpostverify']) {
  76. $_data['modelField']['status'] = 1;
  77. } else {
  78. $_data['modelField']['status'] = 0;
  79. }
  80. $id = 0;
  81. if ($category['type'] == 2) {
  82. $_data['modelFieldExt'] = isset($_data['modelFieldExt']) ? $_data['modelFieldExt'] : [];
  83. try {
  84. $id = $this->CmsModel->addModelData($_data['modelField'], $_data['modelFieldExt']);
  85. } catch (\Exception $ex) {
  86. $this->error($ex->getMessage(), null, ['token' => $this->request->token()]);
  87. }
  88. }
  89. //添加投稿记录
  90. if ($id) {
  91. CmsContentModel::create([
  92. 'catid' => $catid,
  93. 'content_id' => $id,
  94. 'uid' => $_data['modelField']['uid'],
  95. 'username' => $_data['modelField']['username'],
  96. 'create_time' => time(),
  97. 'status' => $_data['modelField']['status'],
  98. ]);
  99. }
  100. if ($_data['modelField']['status'] == 1) {
  101. $this->success('操作成功,内容已通过审核!', url('published'));
  102. } else {
  103. $this->success('操作成功,等待管理员审核!', url('published'));
  104. }
  105. } else {
  106. $step = $this->request->param('step/d', 1);
  107. if ($step == 1) {
  108. return $this->fetch('/content_declaration');
  109. }
  110. $catid = $this->request->param('catid/d', 0);
  111. $tree = new \util\Tree();
  112. $str = "<option value=@catidurl @selected @disabled>@spacer @catname</option>";
  113. $array = Db::name('Category')->order('listorder DESC, id DESC')->column('*', 'id');
  114. foreach ($array as $k => $v) {
  115. if ($v['id'] == $catid) {
  116. $array[$k]['selected'] = "selected";
  117. }
  118. //含子栏目和单页不可以发表
  119. if ($v['child'] == 1 || $v['type'] == 1) {
  120. $array[$k]['disabled'] = "disabled";
  121. $array[$k]['catidurl'] = url('publish', ['step' => 2]);
  122. } else {
  123. $array[$k]['disabled'] = "";
  124. $array[$k]['catidurl'] = url('publish', ['step' => 2, 'catid' => $v['id']]);
  125. }
  126. }
  127. $tree->init($array);
  128. $categoryselect = $tree->getTree(0, $str);
  129. //如果有选择栏目的情况下
  130. if ($catid) {
  131. $category = Db::name('Category')->find($catid);
  132. if (empty($category)) {
  133. $this->error('该栏目不存在!');
  134. }
  135. if ($category['type'] == 2) {
  136. $modelid = $category['modelid'];
  137. $fieldList = Service::getFieldList($modelid);
  138. $this->assign([
  139. 'catid' => $catid,
  140. 'fieldList' => $fieldList,
  141. ]);
  142. }
  143. }
  144. $this->assign("categoryselect", $categoryselect);
  145. return $this->fetch('/content_publish');
  146. }
  147. }
  148. /**
  149. * 编辑内容
  150. */
  151. public function edit()
  152. {
  153. $groupinfo = $this->_check_group_auth($this->auth->groupid);
  154. if ($this->request->isPost()) {
  155. $data = $this->request->param('', '', 'trim,xss_clean');
  156. // 验证数据
  157. $rule = [
  158. 'modelField.title|标题' => 'require|length:3,100',
  159. 'modelField.catid|栏目' => 'require|integer',
  160. '__token__' => 'require|token',
  161. ];
  162. $result = $this->validate($data, $rule);
  163. if (true !== $result) {
  164. $this->error($result, null, ['token' => $this->request->token()]);
  165. }
  166. $id = intval($data['modelField']['id']);
  167. $catid = intval($data['modelField']['catid']);
  168. if (empty($id) || empty($catid)) {
  169. $this->error("请指定栏目ID!");
  170. }
  171. $category = Db::name('Category')->find($catid);
  172. if (empty($category)) {
  173. $this->error('该栏目不存在!');
  174. }
  175. $catidPrv = Db::name('category_priv')->where(["catid" => $catid, "roleid" => $this->auth->groupid, "is_admin" => 0, "action" => "add"])->find();
  176. if (empty($catidPrv)) {
  177. $this->error("您没有该栏目投稿权限!");
  178. }
  179. $fields = Db::name('model_field')->where('modelid', $category['modelid'])->where('isadd', 1)->column('name,ifsystem');
  180. $_data = [];
  181. foreach ($fields as $k => $v) {
  182. if (1 == $v && isset($data['modelField'][$k])) {
  183. $_data['modelField'][$k] = $data['modelField'][$k];
  184. } elseif (0 == $v && isset($data['modelFieldExt'][$k])) {
  185. $_data['modelFieldExt'][$k] = $data['modelFieldExt'][$k];
  186. }
  187. }
  188. //判断会员组投稿是否需要审核
  189. if ($groupinfo['allowpostverify']) {
  190. $_data['modelField']['status'] = 1;
  191. } else {
  192. $_data['modelField']['status'] = 0;
  193. }
  194. if ($category['type'] == 2) {
  195. $_data['modelFieldExt'] = isset($_data['modelFieldExt']) ? $_data['modelFieldExt'] : [];
  196. try {
  197. $this->CmsModel->editModelData($_data['modelField'], $_data['modelFieldExt']);
  198. } catch (\Exception $ex) {
  199. $this->error($ex->getMessage());
  200. }
  201. }
  202. if ($_data['modelField']['status'] == 1) {
  203. CmsContentModel::where(['content_id' => $id, 'catid' => $catid])->update(['status' => 1]);
  204. $this->success('编辑成功,内容已通过审核!', url('published'));
  205. } else {
  206. CmsContentModel::where(['content_id' => $id, 'catid' => $catid])->update(['status' => 0]);
  207. $this->success('编辑成功,等待管理员审核!', url('published'));
  208. }
  209. } else {
  210. $id = $this->request->param('id/d', 0);
  211. $info = CmsContentModel::where(['uid' => $this->auth->id, 'id' => $id])->find();
  212. if (empty($info)) {
  213. $this->error('稿件不存在!');
  214. }
  215. $catid = $info['catid'];
  216. //取得栏目数据
  217. $category = getCategory($catid);
  218. if (empty($category)) {
  219. $this->error('该栏目不存在!', url('publish', ['step' => 2]));
  220. }
  221. //模型ID
  222. $modelid = (int) $category['modelid'];
  223. //判断是否终极栏目
  224. if ($category['child'] || $category['type'] == 0) {
  225. $this->error("该栏目不允许投稿!", url('publish', ['step' => 2]));
  226. }
  227. $fieldList = Service::getFieldList($modelid, $info['content_id']);
  228. $this->assign([
  229. 'catid' => $catid,
  230. 'fieldList' => $fieldList,
  231. ]);
  232. return $this->fetch('/content_edit');
  233. }
  234. }
  235. public function published()
  236. {
  237. if ($this->request->isAjax()) {
  238. $limit = $this->request->param('limit/d', 10);
  239. $page = $this->request->param('page/d', 10);
  240. $type = $this->request->param('type/s', "");
  241. $where = ['uid' => $this->auth->id];
  242. if ('check' == $type) {
  243. $where['status'] = 1;
  244. }
  245. if ('checking' == $type) {
  246. $where['status'] = 0;
  247. }
  248. $total = CmsContentModel::where($where)->count();
  249. $_list = CmsContentModel::where($where)->page($page, $limit)->order(["id" => "DESC"])->select();
  250. foreach ($_list as $k => $v) {
  251. $modelid = getCategory($v['catid'], 'modelid');
  252. $tablename = ucwords(getModel($modelid, 'tablename'));
  253. $info = Db::name($tablename)->where(["id" => $v['content_id'], "sysadd" => 0])->find();
  254. if ($info) {
  255. $_list[$k]['url'] = buildContentUrl($v['catid'], $v['content_id'], $info['url']);
  256. $_list[$k]['title'] = $info['title'];
  257. $_list[$k]['catname'] = getCategory($v['catid'], 'catname');
  258. }
  259. }
  260. $result = ["code" => 0, "count" => $total, "data" => $_list];
  261. return json($result);
  262. }
  263. return $this->fetch('/content_published');
  264. }
  265. //订单列表
  266. public function order()
  267. {
  268. if ($this->request->isAjax()) {
  269. $limit = $this->request->param('limit/d', 10);
  270. $page = $this->request->param('page/d', 1);
  271. $_list = OrderModel::where('user_id', $this->auth->id)->page($page, $limit)->order('id DESC')->select();
  272. $total = OrderModel::where('user_id', $this->auth->id)->count();
  273. $result = ["code" => 0, "count" => $total, "data" => $_list];
  274. return json($result);
  275. } else {
  276. return $this->fetch('/order_list');
  277. }
  278. }
  279. //删除
  280. public function del()
  281. {
  282. $id = $this->request->param('id/d', 0);
  283. if (empty($id)) {
  284. $this->error('请指定需要删除的信息!');
  285. }
  286. //信息
  287. $info = CmsContentModel::where('id', $id)->find();
  288. //只能删除自己的 且 未通过审核的
  289. if ($info && $info['uid'] == $this->auth->id && $info['status'] != 1) {
  290. //取得栏目信息
  291. $category = getCategory($info['catid']);
  292. if (!$category) {
  293. $this->success('栏目不存在!');
  294. }
  295. try {
  296. $this->CmsModel->deleteModelData($category['modelid'], $info['content_id']);
  297. } catch (\Exception $ex) {
  298. $this->error($ex->getMessage());
  299. }
  300. $this->success('删除成功!');
  301. } else {
  302. $this->error('对不起,你无权删除!');
  303. }
  304. }
  305. //检查会员组权限
  306. private function _check_group_auth($groupid)
  307. {
  308. $grouplist = cache("Member_Group"); //会员模型
  309. if (!$grouplist[$groupid]['allowpost']) {
  310. $this->error('你没有权限投稿,请升级会员组!');
  311. }
  312. return $grouplist[$groupid];
  313. }
  314. }