WaterCate.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\water;
  8. use app\admin\controller\AuthController;
  9. use crmeb\services\{ExpressService,
  10. JsonService,
  11. JsonService as Json,
  12. MiniProgramService,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util};
  17. use think\facade\Route as Url;
  18. use think\facade\Validate;
  19. Use app\admin\model\water\WaterCate as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterCate extends AuthController
  26. {
  27. /**
  28. * @return mixed
  29. */
  30. public function index()
  31. {
  32. return $this->fetch();
  33. }
  34. public function list()
  35. {
  36. $where = Util::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ['name', ''],
  40. ['role', ''],
  41. ['type', ''],
  42. ['gc', ''],
  43. ]);
  44. return Json::successlayui(model::list($where));
  45. }
  46. /**
  47. * 显示创建资源表单页.
  48. *
  49. * @return \think\Response
  50. */
  51. public function create($id = 0)
  52. {
  53. $f = [];
  54. $f[] = Form::input('name', '分类名称');
  55. $f[] = Form::select('type', '选择分类', '')->options([
  56. ['value' => 0, 'label' => '请选择分类'],
  57. ['value' => 1, 'label' => '顶板'],
  58. ['value' => 2, 'label' => '侧板'],
  59. ['value' => 3, 'label' => '拉筋'],
  60. ['value' => 4, 'label' => '底板'],
  61. ['value' => 5, 'label' => '立柱'],
  62. ['value' => 6, 'label' => '辅拉'],
  63. ['value' => 7, 'label' => '保温'],
  64. ['value' => 8, 'label' => '槽钢'],
  65. ['value' => 9, 'label' => '扶梯管'],
  66. ])->filterable(true);
  67. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  68. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  69. $this->assign(compact('form'));
  70. return $this->fetch('public/form-builder');
  71. }
  72. public function save()
  73. {
  74. $model = new model;
  75. $data = Util::postMore([
  76. 'name',
  77. 'type',
  78. 'is_gc',
  79. ]);
  80. $validate = Validate::rule([
  81. 'name' => 'require',
  82. 'type' => 'require',
  83. ]);
  84. $validate->message([
  85. 'name.require' => '名称不能为空',
  86. 'type.require' => '分类不能为空',
  87. ]);
  88. if (!$validate->check($data)) {
  89. return Json::fail($validate->getError());
  90. }
  91. $res = $model->save($data);
  92. if ($res) return Json::successful('添加成功');
  93. return Json::fail('添加失败');
  94. }
  95. /**
  96. * 显示创建资源表单页.
  97. *
  98. * @return \think\Response
  99. */
  100. public function edit($id = 0)
  101. {
  102. $data = model::find($id);
  103. $f = [];
  104. $f[] = Form::input('name', '分类名称', $data['name']);
  105. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  106. ['value' => 0, 'label' => '请选择分类'],
  107. ['value' => 1, 'label' => '顶板'],
  108. ['value' => 2, 'label' => '侧板'],
  109. ['value' => 3, 'label' => '拉筋'],
  110. ['value' => 4, 'label' => '底板'],
  111. ['value' => 5, 'label' => '立柱'],
  112. ['value' => 6, 'label' => '辅拉'],
  113. ['value' => 7, 'label' => '保温'],
  114. ['value' => 8, 'label' => '槽钢'],
  115. ['value' => 9, 'label' => '扶梯管'],
  116. ])->filterable(true);
  117. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  118. $f[] = Form::hidden('id', $id);
  119. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  120. $this->assign(compact('form'));
  121. return $this->fetch('public/form-builder');
  122. }
  123. /**
  124. * 修改
  125. * @return void
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\DbException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. */
  130. public function update()
  131. {
  132. $model = new model;
  133. $data = Util::postMore([
  134. 'name',
  135. 'type',
  136. 'id',
  137. 'is_gc'
  138. ]);
  139. $validate = Validate::rule([
  140. 'title' => 'require',
  141. 'price' => 'require',
  142. ]);
  143. $validate->message([
  144. 'name.require' => '名称不能为空',
  145. 'type.require' => '分类不能为空',
  146. ]);
  147. $details = $model->find($data['id']);
  148. $details['name'] = $data['name'];
  149. $details['type'] = $data['type'];
  150. $details['is_gc'] = $data['is_gc'];
  151. $res = $details->save();
  152. if ($res) return Json::successful('修改成功');
  153. return Json::fail('修改失败');
  154. }
  155. /**
  156. * 删除
  157. * @param $id
  158. * @return void
  159. * @throws \Exception
  160. */
  161. public function delete($id)
  162. {
  163. if (!$id) Json::fail('删除失败');
  164. $model = new model;
  165. $res = model::destroy($id);
  166. if ($res){
  167. return Json::success('删除成功!');
  168. }else{
  169. return Json::fail($model->getErrorInfo());
  170. }
  171. }
  172. /**
  173. * 设置单个产品上架|下架
  174. *
  175. * @return json
  176. */
  177. public function set_show($is_show = '', $id = '')
  178. {
  179. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  180. $res = model::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  181. if ($res) {
  182. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  183. } else {
  184. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  185. }
  186. }
  187. }