DiagnosisCate.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\diagnosis;
  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\diagnosis\DiagnosisCate as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class DiagnosisCate 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', '名称')->required();
  55. $f[] = Form::select('type', '选择类型', '')->options([
  56. ['value' => 1, 'label' => '陪诊'],
  57. ['value' => 2, 'label' => '代办'],
  58. ])->filterable(true)->required();
  59. $f[] = Form::frameImageOne('image', '图标', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  60. $f[] = Form::input('price', '金额')->required();
  61. $f[] = Form::input('reward', '接单奖励')->required();
  62. $f[] = Form::textarea('info', '简介');
  63. $f[] = Form::radio('status', '状态', 1)->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  64. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  65. $this->assign(compact('form'));
  66. return $this->fetch('public/form-builder');
  67. }
  68. public function save()
  69. {
  70. $model = new model;
  71. $data = Util::postMore([
  72. 'name',
  73. 'type',
  74. 'price',
  75. 'status',
  76. 'reward',
  77. 'image',
  78. 'info',
  79. ]);
  80. $res = $model->save($data);
  81. if ($res) return Json::successful('添加成功');
  82. return Json::fail('添加失败');
  83. }
  84. /**
  85. * 显示创建资源表单页.
  86. *
  87. * @return \think\Response
  88. */
  89. public function edit($id = 0)
  90. {
  91. $data = model::find($id);
  92. $f = [];
  93. $f[] = Form::input('name', '分类名称', $data['name'])->required();
  94. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  95. ['value' => 1, 'label' => '陪诊'],
  96. ['value' => 2, 'label' => '代办'],
  97. ])->filterable(true)->required();
  98. $f[] = Form::frameImageOne('image', '图标', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  99. $f[] = Form::input('price', '金额', $data['price'])->required();
  100. $f[] = Form::input('reward', '接单奖励', $data['reward'])->required();
  101. $f[] = Form::radio('status', '状态', (string)$data['status'])->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  102. $f[] = Form::textarea('info', '简介', $data['info']);
  103. $f[] = Form::hidden('id', $id);
  104. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  105. $this->assign(compact('form'));
  106. return $this->fetch('public/form-builder');
  107. }
  108. /**
  109. * 修改
  110. * @return void
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\DbException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. */
  115. public function update()
  116. {
  117. $model = new model;
  118. $data = Util::postMore([
  119. 'name',
  120. 'type',
  121. 'price',
  122. 'status',
  123. 'reward',
  124. 'image',
  125. 'info',
  126. 'id'
  127. ]);
  128. $details = $model->find($data['id']);
  129. $details['name'] = $data['name'];
  130. $details['type'] = $data['type'];
  131. $details['price'] = $data['price'];
  132. $details['status'] = $data['status'];
  133. $details['reward'] = $data['reward'];
  134. $details['image'] = $data['image'];
  135. $details['info'] = $data['info'];
  136. $res = $details->save();
  137. if ($res) return Json::successful('修改成功');
  138. return Json::fail('修改失败');
  139. }
  140. /**
  141. * 删除
  142. * @param $id
  143. * @return void
  144. * @throws \Exception
  145. */
  146. public function delete($id)
  147. {
  148. if (!$id) return Json::fail('删除失败');
  149. $model = new model;
  150. $res = model::destroy($id);
  151. if ($res){
  152. return Json::success('删除成功!');
  153. }else{
  154. return Json::fail($model->getErrorInfo());
  155. }
  156. }
  157. /**
  158. * 设置单个产品上架|下架
  159. *
  160. * @return json
  161. */
  162. public function set_show($is_show = '', $id = '')
  163. {
  164. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  165. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  166. if ($res) {
  167. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  168. } else {
  169. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  170. }
  171. }
  172. }