UserPartake.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use app\admin\model\User;
  6. use crmeb\services\{ExpressService,
  7. FormBuilder,
  8. JsonService,
  9. MiniProgramService,
  10. upload\Upload,
  11. WechatService,
  12. FormBuilder as Form,
  13. CacheService,
  14. UtilService as Util,
  15. JsonService as Json};
  16. use app\admin\model\system\{SystemAdmin,
  17. SystemAttachment as SystemAttachmentModel,
  18. SystemAttachmentCategory as Category};
  19. use think\Db;
  20. use think\facade\Route as Url;
  21. use think\facade\Validate;
  22. use app\admin\model\user\UserPartake as model;
  23. class UserPartake extends AuthController
  24. {
  25. public function index()
  26. {
  27. $this->assign('admin', $this->adminInfo);
  28. return $this->fetch();
  29. }
  30. public function list()
  31. {
  32. $where = Util::getMore([
  33. ['status', ''],
  34. ['page', 1],
  35. ['limit', 20],
  36. ['name'],
  37. ]);
  38. $data = model::list($where);
  39. return Json::successlayui($data);
  40. }
  41. /**
  42. * 显示创建资源表单页.
  43. *
  44. * @return \think\Response
  45. */
  46. public function create($id = 0)
  47. {
  48. $f = [];
  49. $f[] = Form::input('name', '名称')->col(12);
  50. $f[] = Form::textarea('info', '简介');
  51. $f[] = Form::number('number', '达标额度')->col(12);
  52. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  53. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  54. $this->assign(compact('form'));
  55. return $this->fetch('public/form-builder');
  56. }
  57. public function save()
  58. {
  59. $mode = new model;
  60. $data = Util::postMore([
  61. 'name',
  62. 'info',
  63. 'number',
  64. 'status',
  65. ]);
  66. $validate = Validate::rule('name', 'require')->rule([
  67. 'name' => 'require',
  68. 'number' => 'require',
  69. ]);
  70. $validate->message([
  71. 'name.require' => '名称不能为空',
  72. 'number.require' => '达标额度不能为空',
  73. ]);
  74. if (!$validate->check($data)) {
  75. return Json::fail($validate->getError());
  76. }
  77. $res = $mode->save($data);
  78. if ($res){
  79. return Json::success('添加成功!');
  80. }else{
  81. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  82. }
  83. }
  84. /**
  85. * 删除
  86. * @param $id
  87. * @return void
  88. * @throws \Exception
  89. */
  90. public function delete($id)
  91. {
  92. if (!$id) Json::fail('删除失败');
  93. $model = new model;
  94. $res = $model->where('id', $id)->delete();
  95. if ($res){
  96. return Json::success('删除成功!');
  97. }else{
  98. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  99. }
  100. }
  101. public function set_status($id, $status)
  102. {
  103. if (empty($id))return Json::fail('修改失败');
  104. $res = model::update(['status' => $status, 'id' => $id]);
  105. if ($res){
  106. return Json::success('修改成功!');
  107. }else{
  108. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  109. }
  110. }
  111. public function edit($id)
  112. {
  113. if (!$id) Json::fail('数据不存在');
  114. $data = model::find($id);
  115. $f = [];
  116. $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
  117. $f[] = Form::textarea('info', '介绍',$data->getData('info'));
  118. $f[] = Form::number('number', '达标额度', $data->getData('number'))->col(12);
  119. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  120. $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
  121. $this->assign(compact('form'));
  122. return $this->fetch('public/form-builder');
  123. }
  124. public function update()
  125. {
  126. $data = Util::postMore([
  127. 'id',
  128. 'name',
  129. 'info',
  130. 'status',
  131. 'number',
  132. ]);
  133. $validate = Validate::rule('name', 'require')->rule([
  134. 'name' => 'require',
  135. 'number' => 'require',
  136. ]);
  137. $validate->message([
  138. 'name.require' => '名称不能为空',
  139. 'number.require' => '达标数量不能为空',
  140. ]);
  141. if (!$validate->check($data)) {
  142. return Json::fail($validate->getError());
  143. }
  144. $res = model::update($data);
  145. if ($res){
  146. return Json::success('修改成功!');
  147. }else{
  148. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  149. }
  150. }
  151. }