控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\common\controller\Adminbase;
  17. use app\member\service\User;
  18. class Member extends Adminbase
  19. {
  20. protected $searchFields = 'id,username,nickname';
  21. //初始化
  22. protected function initialize()
  23. {
  24. parent::initialize();
  25. $this->modelClass = new MemberModel;
  26. $this->UserService = User::instance();
  27. $this->groupCache = cache("Member_Group"); //会员模型
  28. }
  29. /**
  30. * 会员列表
  31. */
  32. public function index()
  33. {
  34. $this->relationSearch = true;
  35. if ($this->request->isAjax()) {
  36. //如果发送的来源是Selectpage,则转发到Selectpage
  37. if ($this->request->request('keyField')) {
  38. return $this->selectpage();
  39. }
  40. list($page, $limit, $where) = $this->buildTableParames();
  41. $_list = $this->modelClass
  42. ->withJoin('group')
  43. ->where($where)
  44. ->page($page, $limit)
  45. ->select();
  46. $total = $this->modelClass
  47. ->withJoin('group')
  48. ->where($where)
  49. ->count();
  50. $result = ["code" => 0, "count" => $total, "data" => $_list];
  51. return json($result);
  52. }
  53. return $this->fetch();
  54. }
  55. /**
  56. * 审核会员
  57. */
  58. public function userverify()
  59. {
  60. if ($this->request->isAjax()) {
  61. list($page, $limit, $where) = $this->buildTableParames();
  62. $_list = $this->modelClass->where($where)->where('status', '<>', 1)->page($page, $limit)->select();
  63. $total = $this->modelClass->where($where)->where('status', '<>', 1)->count();
  64. $result = ["code" => 0, "count" => $total, "data" => $_list];
  65. return json($result);
  66. }
  67. return $this->fetch();
  68. }
  69. /**
  70. * 会员增加
  71. */
  72. public function add()
  73. {
  74. if ($this->request->isPost()) {
  75. $data = $this->request->post();
  76. $result = $this->validate($data, 'app\admin\validate\member\Member');
  77. if (true !== $result) {
  78. return $this->error($result);
  79. }
  80. $data['overduedate'] = $data['overduedate'] ? strtotime($data['overduedate']) : null;
  81. if ($this->UserService->userRegister($data['username'], $data['password'], $data['email'], $data['mobile'], $data)) {
  82. $this->success("添加会员成功!", url("index"));
  83. } else {
  84. //$this->UserService->delete($memberinfo['userid']);
  85. $this->error($this->UserService->getError() ?: '添加会员失败!');
  86. }
  87. } else {
  88. foreach ($this->groupCache as $_key => $_value) {
  89. $groupCache[$_key] = $_value['name'];
  90. }
  91. $this->assign('groupCache', $groupCache);
  92. return $this->fetch();
  93. }
  94. }
  95. /**
  96. * 会员编辑
  97. */
  98. public function edit()
  99. {
  100. if ($this->request->isPost()) {
  101. $userid = $this->request->param('id/d', 0);
  102. $data = $this->request->post();
  103. $result = $this->validate($data, 'app\admin\validate\member\Member.edit');
  104. if (true !== $result) {
  105. return $this->error($result);
  106. }
  107. //获取用户信息
  108. $userinfo = MemberModel::get($userid);
  109. if (empty($userinfo)) {
  110. $this->error('该会员不存在!');
  111. }
  112. //修改基本资料
  113. if ($userinfo['username'] != $data['username'] || !empty($data['password']) || $userinfo['email'] != $data['email']) {
  114. $res = $this->modelClass->userEdit($userinfo['username'], '', $data['password'], $data['email'], 1);
  115. if (!$res) {
  116. $this->error($this->modelClass->getError());
  117. }
  118. }
  119. unset($data['username'], $data['password'], $data['email']);
  120. $data['overduedate'] = $data['overduedate'] ? strtotime($data['overduedate']) : null;
  121. //更新除基本资料外的其他信息
  122. if (false === $this->modelClass->allowField(true)->save($data, ['id' => $userid])) {
  123. $this->error('更新失败!');
  124. }
  125. $this->success("更新成功!", url("index"));
  126. } else {
  127. $userid = $this->request->param('id/d', 0);
  128. $data = $this->modelClass->get($userid);
  129. if (empty($data)) {
  130. $this->error("该会员不存在!");
  131. }
  132. foreach ($this->groupCache as $_key => $_value) {
  133. $groupCache[$_key] = $_value['name'];
  134. }
  135. $this->assign('groupCache', $groupCache);
  136. $this->assign("data", $data);
  137. return $this->fetch();
  138. }
  139. }
  140. /**
  141. * 会员删除
  142. */
  143. public function del()
  144. {
  145. $ids = $this->request->param('id/a', null);
  146. if (empty($ids)) {
  147. $this->error('请选择需要删除的会员!');
  148. }
  149. if (!is_array($ids)) {
  150. $ids = [0 => $ids];
  151. }
  152. foreach ($ids as $uid) {
  153. $this->UserService->delete($uid);
  154. }
  155. $this->success("删除成功!");
  156. }
  157. /**
  158. * 审核会员
  159. */
  160. public function pass()
  161. {
  162. $ids = $this->request->param('id/a', null);
  163. if (empty($ids)) {
  164. $this->error('请选择需要审核的会员!');
  165. }
  166. if (!is_array($ids)) {
  167. $ids = [0 => $ids];
  168. }
  169. foreach ($ids as $uid) {
  170. $info = MemberModel::where('id', $uid)->update(['status' => 1]);
  171. }
  172. $this->success("审核成功!");
  173. }
  174. }