Out.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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\order\StoreOrder;
  6. use app\admin\model\User;
  7. use crmeb\services\{ExpressService,
  8. FormBuilder,
  9. JsonService,
  10. MiniProgramService,
  11. upload\Upload,
  12. WechatService,
  13. FormBuilder as Form,
  14. CacheService,
  15. UtilService as Util,
  16. JsonService as Json
  17. };
  18. use app\admin\model\system\{SystemAdmin,
  19. SystemAttachment as SystemAttachmentModel,
  20. SystemAttachmentCategory as Category
  21. };
  22. use think\Db;
  23. use think\facade\Route as Url;
  24. use think\facade\Validate;
  25. use app\admin\model\user\Out as model;
  26. class Out extends AuthController
  27. {
  28. public function index()
  29. {
  30. $this->assign('admin', $this->adminInfo);
  31. return $this->fetch();
  32. }
  33. public function list()
  34. {
  35. $where = Util::getMore([
  36. ['status', ''],
  37. ['page', 1],
  38. ['limit', 20],
  39. ['auction'],
  40. ['uid'],
  41. ['null']
  42. ]);
  43. $data = model::list($where);
  44. return Json::successlayui($data);
  45. }
  46. /**
  47. * 显示创建资源表单页.
  48. *
  49. * @return \think\Response
  50. */
  51. public function create($id = 0)
  52. {
  53. $f = [];
  54. $f[] = Form::input('name', '名称')->col(12);
  55. $f[] = Form::textarea('info', '简介');
  56. $f[] = Form::number('number', '达标额度')->col(12);
  57. $f[] = Form::frameImages('pics', '轮播图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'pics')))->maxLength(5)->icon('image')->width('100%')->height('500px');
  58. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  59. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  60. $this->assign(compact('form'));
  61. return $this->fetch('public/form-builder');
  62. }
  63. public function save()
  64. {
  65. $mode = new model;
  66. $data = Util::postMore([
  67. 'name',
  68. 'info',
  69. 'number',
  70. 'status',
  71. ['pics', []]
  72. ]);
  73. $validate = Validate::rule('name', 'require')->rule([
  74. 'name' => 'require',
  75. 'number' => 'require',
  76. ]);
  77. $validate->message([
  78. 'name.require' => '名称不能为空',
  79. 'number.require' => '达标额度不能为空',
  80. ]);
  81. $data['pics'] = implode(',', $data['pics']);
  82. if (!$validate->check($data)) {
  83. return Json::fail($validate->getError());
  84. }
  85. $res = $mode->save($data);
  86. if ($res) {
  87. return Json::success('添加成功!');
  88. } else {
  89. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  90. }
  91. }
  92. /**
  93. * 删除
  94. * @param $id
  95. * @return void
  96. * @throws \Exception
  97. */
  98. public function delete($id)
  99. {
  100. if (!$id) Json::fail('删除失败');
  101. $model = new model;
  102. $res = $model->where('id', $id)->delete();
  103. if ($res) {
  104. return Json::success('删除成功!');
  105. } else {
  106. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  107. }
  108. }
  109. public function set_status($id, $status)
  110. {
  111. if (empty($id)) return Json::fail('修改失败');
  112. $res = model::update(['status' => $status, 'id' => $id]);
  113. if ($res) {
  114. return Json::success('修改成功!');
  115. } else {
  116. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  117. }
  118. }
  119. public function edit($id)
  120. {
  121. if (!$id) Json::fail('数据不存在');
  122. $data = model::find($id);
  123. $f = [];
  124. $f[] = Form::input('name', '名称', $data->getData('name'))->col(12);
  125. $f[] = Form::textarea('info', '介绍', $data->getData('info'));
  126. $f[] = Form::frameImages('pics', '轮播图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'pics')), explode(',', $data->getData('pics')))->maxLength(5)->icon('image')->width('100%')->height('500px');
  127. $f[] = Form::number('number', '达标额度', $data->getData('number'))->col(12);
  128. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  129. $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
  130. $this->assign(compact('form'));
  131. return $this->fetch('public/form-builder');
  132. }
  133. public function update()
  134. {
  135. $data = Util::postMore([
  136. 'id',
  137. 'name',
  138. 'info',
  139. 'status',
  140. 'number',
  141. ['pics', []]
  142. ]);
  143. $validate = Validate::rule('name', 'require')->rule([
  144. 'name' => 'require',
  145. 'number' => 'require',
  146. ]);
  147. $validate->message([
  148. 'name.require' => '名称不能为空',
  149. 'number.require' => '达标数量不能为空',
  150. ]);
  151. $data['pics'] = implode(',', $data['pics']);
  152. if (!$validate->check($data)) {
  153. return Json::fail($validate->getError());
  154. }
  155. $res = model::update($data);
  156. if ($res) {
  157. return Json::success('修改成功!');
  158. } else {
  159. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  160. }
  161. }
  162. public function edit_content($id)
  163. {
  164. if (!$id) return $this->failed('数据不存在');
  165. $seckill = model::get($id);
  166. if (!$seckill) return Json::fail('数据不存在!');
  167. $this->assign([
  168. 'content' => htmlspecialchars_decode($seckill['content']),
  169. 'field' => 'content',
  170. 'action' => Url::buildUrl('change_field', ['id' => $id, 'field' => 'content'])
  171. ]);
  172. return $this->fetch('public/edit_content');
  173. }
  174. public function change_field($id)
  175. {
  176. if (!$id) return $this->failed('数据不存在');
  177. $seckill = model::get($id);
  178. if (!$seckill) return Json::fail('数据不存在!');
  179. $data['content'] = request()->post('content');
  180. $res = model::edit($data, $id);
  181. if ($res)
  182. return Json::successful('添加成功');
  183. else
  184. return Json::fail('添加失败');
  185. }
  186. /**
  187. * 显示创建资源表单页.
  188. *
  189. * @return \think\Response
  190. */
  191. public function user_push($uid = 0)
  192. {
  193. return $this->fetch();
  194. }
  195. public function user_push_list()
  196. {
  197. $where = Util::getMore([
  198. ['status', ''],
  199. ['page', 1],
  200. ['limit', 20],
  201. ['auction'],
  202. ['uid'],
  203. ['spread_uid']
  204. ]);
  205. $data = StoreOrder::list($where);
  206. return Json::successlayui($data);
  207. }
  208. }