WaterCate.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. ]);
  43. return Json::successlayui(model::list($where));
  44. }
  45. /**
  46. * 显示创建资源表单页.
  47. *
  48. * @return \think\Response
  49. */
  50. public function create($id = 0)
  51. {
  52. $f = [];
  53. $f[] = Form::input('name', '分类名称');
  54. $f[] = Form::select('type', '选择分类', '')->options([
  55. ['value' => 0, 'label' => '请选择分类'],
  56. ['value' => 1, 'label' => '顶板'],
  57. ['value' => 2, 'label' => '侧板'],
  58. ['value' => 3, 'label' => '拉筋'],
  59. ['value' => 4, 'label' => '底板'],
  60. ['value' => 5, 'label' => '立柱'],
  61. ['value' => 6, 'label' => '辅拉'],
  62. ['value' => 7, 'label' => '保温'],
  63. ['value' => 8, 'label' => '槽钢'],
  64. ['value' => 9, 'label' => '扶梯管'],
  65. ])->filterable(true);
  66. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  67. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  68. $this->assign(compact('form'));
  69. return $this->fetch('public/form-builder');
  70. }
  71. public function save()
  72. {
  73. $model = new model;
  74. $data = Util::postMore([
  75. 'name',
  76. 'type',
  77. 'is_gc',
  78. ]);
  79. $validate = Validate::rule([
  80. 'name' => 'require',
  81. 'type' => 'require',
  82. ]);
  83. $validate->message([
  84. 'name.require' => '名称不能为空',
  85. 'type.require' => '分类不能为空',
  86. ]);
  87. if (!$validate->check($data)) {
  88. return Json::fail($validate->getError());
  89. }
  90. $res = $model->save($data);
  91. if ($res) return Json::successful('添加成功');
  92. return Json::fail('添加失败');
  93. }
  94. /**
  95. * 显示创建资源表单页.
  96. *
  97. * @return \think\Response
  98. */
  99. public function edit($id = 0)
  100. {
  101. $data = model::find($id);
  102. $f = [];
  103. $f[] = Form::input('name', '分类名称', $data['name']);
  104. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  105. ['value' => 0, 'label' => '请选择分类'],
  106. ['value' => 1, 'label' => '顶板'],
  107. ['value' => 2, 'label' => '侧板'],
  108. ['value' => 3, 'label' => '拉筋'],
  109. ['value' => 4, 'label' => '底板'],
  110. ['value' => 5, 'label' => '立柱'],
  111. ['value' => 6, 'label' => '辅拉'],
  112. ['value' => 7, 'label' => '保温'],
  113. ['value' => 8, 'label' => '槽钢'],
  114. ['value' => 9, 'label' => '扶梯管'],
  115. ])->filterable(true);
  116. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  117. $f[] = Form::hidden('id', $id);
  118. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  119. $this->assign(compact('form'));
  120. return $this->fetch('public/form-builder');
  121. }
  122. /**
  123. * 修改
  124. * @return void
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\DbException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. */
  129. public function update()
  130. {
  131. $model = new model;
  132. $data = Util::postMore([
  133. 'name',
  134. 'type',
  135. 'id',
  136. 'is_gc'
  137. ]);
  138. $validate = Validate::rule([
  139. 'title' => 'require',
  140. 'price' => 'require',
  141. ]);
  142. $validate->message([
  143. 'name.require' => '名称不能为空',
  144. 'type.require' => '分类不能为空',
  145. ]);
  146. $details = $model->find($data['id']);
  147. $details['name'] = $data['name'];
  148. $details['type'] = $data['type'];
  149. $details['is_gc'] = $data['is_gc'];
  150. $res = $details->save();
  151. if ($res) return Json::successful('修改成功');
  152. return Json::fail('修改失败');
  153. }
  154. /**
  155. * 删除
  156. * @param $id
  157. * @return void
  158. * @throws \Exception
  159. */
  160. public function delete($id)
  161. {
  162. if (!$id) Json::fail('删除失败');
  163. $model = new model;
  164. $res = model::destroy($id);
  165. if ($res){
  166. return Json::success('删除成功!');
  167. }else{
  168. return Json::fail($model->getErrorInfo());
  169. }
  170. }
  171. /**
  172. * 设置单个产品上架|下架
  173. *
  174. * @return json
  175. */
  176. public function set_show($is_show = '', $id = '')
  177. {
  178. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  179. $res = model::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  180. if ($res) {
  181. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  182. } else {
  183. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  184. }
  185. }
  186. }