Out.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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\Out as model;
  23. class Out 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. ['auction'],
  37. ['uid'],
  38. ['null']
  39. ]);
  40. $data = model::list($where);
  41. return Json::successlayui($data);
  42. }
  43. /**
  44. * 显示创建资源表单页.
  45. *
  46. * @return \think\Response
  47. */
  48. public function create($id = 0)
  49. {
  50. $f = [];
  51. $f[] = Form::input('name', '名称')->col(12);
  52. $f[] = Form::textarea('info', '简介');
  53. $f[] = Form::number('number', '达标额度')->col(12);
  54. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  55. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  56. $this->assign(compact('form'));
  57. return $this->fetch('public/form-builder');
  58. }
  59. public function save()
  60. {
  61. $mode = new model;
  62. $data = Util::postMore([
  63. 'name',
  64. 'info',
  65. 'number',
  66. 'status',
  67. ]);
  68. $validate = Validate::rule('name', 'require')->rule([
  69. 'name' => 'require',
  70. 'number' => 'require',
  71. ]);
  72. $validate->message([
  73. 'name.require' => '名称不能为空',
  74. 'number.require' => '达标额度不能为空',
  75. ]);
  76. if (!$validate->check($data)) {
  77. return Json::fail($validate->getError());
  78. }
  79. $res = $mode->save($data);
  80. if ($res){
  81. return Json::success('添加成功!');
  82. }else{
  83. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  84. }
  85. }
  86. /**
  87. * 删除
  88. * @param $id
  89. * @return void
  90. * @throws \Exception
  91. */
  92. public function delete($id)
  93. {
  94. if (!$id) Json::fail('删除失败');
  95. $model = new model;
  96. $res = $model->where('id', $id)->delete();
  97. if ($res){
  98. return Json::success('删除成功!');
  99. }else{
  100. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  101. }
  102. }
  103. public function set_status($id, $status)
  104. {
  105. if (empty($id))return Json::fail('修改失败');
  106. $res = model::update(['status' => $status, 'id' => $id]);
  107. if ($res){
  108. return Json::success('修改成功!');
  109. }else{
  110. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  111. }
  112. }
  113. public function edit($id)
  114. {
  115. if (!$id) Json::fail('数据不存在');
  116. $data = model::find($id);
  117. $f = [];
  118. $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
  119. $f[] = Form::textarea('info', '介绍',$data->getData('info'));
  120. $f[] = Form::number('number', '达标额度', $data->getData('number'))->col(12);
  121. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  122. $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
  123. $this->assign(compact('form'));
  124. return $this->fetch('public/form-builder');
  125. }
  126. public function update()
  127. {
  128. $data = Util::postMore([
  129. 'id',
  130. 'name',
  131. 'info',
  132. 'status',
  133. 'number',
  134. ]);
  135. $validate = Validate::rule('name', 'require')->rule([
  136. 'name' => 'require',
  137. 'number' => 'require',
  138. ]);
  139. $validate->message([
  140. 'name.require' => '名称不能为空',
  141. 'number.require' => '达标数量不能为空',
  142. ]);
  143. if (!$validate->check($data)) {
  144. return Json::fail($validate->getError());
  145. }
  146. $res = model::update($data);
  147. if ($res){
  148. return Json::success('修改成功!');
  149. }else{
  150. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  151. }
  152. }
  153. }