控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\admin\controller\member;
  15. use app\admin\model\member\Member as MemberModel;
  16. use app\admin\model\member\MemberGroup as MemberGroup;
  17. use app\common\controller\Adminbase;
  18. use think\exception\PDOException;
  19. use think\exception\ValidateException;
  20. class Group extends Adminbase
  21. {
  22. protected $modelValidate = true;
  23. //初始化
  24. protected function initialize()
  25. {
  26. parent::initialize();
  27. $this->modelClass = new MemberGroup;
  28. }
  29. /**
  30. * 会员组列表
  31. */
  32. public function index()
  33. {
  34. if ($this->request->isAjax()) {
  35. $list = $this->modelClass->order(["listorder" => "DESC", "id" => "DESC"])->select();
  36. foreach ($list as $k => $v) {
  37. //统计会员总数
  38. $list[$k]['count'] = MemberModel::where(["groupid" => $v['id']])->count('id');
  39. }
  40. $result = ["code" => 0, "data" => $list];
  41. return json($result);
  42. }
  43. //dump(cache('Member_Group'));
  44. return $this->fetch();
  45. }
  46. /**
  47. * 会员组编辑
  48. */
  49. public function edit()
  50. {
  51. $id = $this->request->param('id/d', 0);
  52. $row = $this->modelClass->get($id);
  53. if (!$row) {
  54. $this->error('记录未找到');
  55. }
  56. if ($this->request->isPost()) {
  57. $params = $this->request->post('row/a');
  58. $params['allowpost'] = $params['allowpost'] ?? 0;
  59. $params['allowpostverify'] = $params['allowpostverify'] ?? 0;
  60. $params['allowupgrade'] = $params['allowupgrade'] ?? 0;
  61. $params['allowsendmessage'] = $params['allowsendmessage'] ?? 0;
  62. $params['allowattachment'] = $params['allowattachment'] ?? 0;
  63. $params['allowsearch'] = $params['allowsearch'] ?? 0;
  64. $result = false;
  65. try {
  66. //是否采用模型验证
  67. if ($this->modelValidate) {
  68. $name = str_replace("\\model\\", "\\validate\\", get_class($this->modelClass));
  69. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  70. $this->validateFailException(true)->validate($params, $validate);
  71. }
  72. $result = $row->allowField(true)->save($params);
  73. } catch (ValidateException $e) {
  74. $this->error($e->getMessage());
  75. } catch (PDOException $e) {
  76. $this->error($e->getMessage());
  77. } catch (\Exception $e) {
  78. $this->error($e->getMessage());
  79. }
  80. if ($result !== false) {
  81. $this->success('修改成功');
  82. } else {
  83. $this->error('未更新任何行');
  84. }
  85. } else {
  86. $this->assign("data", $row);
  87. return $this->fetch();
  88. }
  89. }
  90. }