DiagnosisCate.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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::input('price', '金额')->required();
  60. $f[] = Form::input('reward', '接单奖励')->required();
  61. $f[] = Form::radio('status', '状态', 1)->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  62. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  63. $this->assign(compact('form'));
  64. return $this->fetch('public/form-builder');
  65. }
  66. public function save()
  67. {
  68. $model = new model;
  69. $data = Util::postMore([
  70. 'name',
  71. 'type',
  72. 'price',
  73. 'status',
  74. 'reward',
  75. ]);
  76. $res = $model->save($data);
  77. if ($res) return Json::successful('添加成功');
  78. return Json::fail('添加失败');
  79. }
  80. /**
  81. * 显示创建资源表单页.
  82. *
  83. * @return \think\Response
  84. */
  85. public function edit($id = 0)
  86. {
  87. $data = model::find($id);
  88. $f = [];
  89. $f[] = Form::input('name', '分类名称', $data['name'])->required();
  90. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  91. ['value' => 1, 'label' => '陪诊'],
  92. ['value' => 2, 'label' => '代办'],
  93. ])->filterable(true)->required();
  94. $f[] = Form::input('price', '金额', $data['price'])->required();
  95. $f[] = Form::input('reward', '接单奖励', $data['reward'])->required();
  96. $f[] = Form::radio('status', '状态', (string)$data['status'])->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  97. $f[] = Form::hidden('id', $id);
  98. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  99. $this->assign(compact('form'));
  100. return $this->fetch('public/form-builder');
  101. }
  102. /**
  103. * 修改
  104. * @return void
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function update()
  110. {
  111. $model = new model;
  112. $data = Util::postMore([
  113. 'name',
  114. 'type',
  115. 'price',
  116. 'status',
  117. 'reward',
  118. 'id'
  119. ]);
  120. $details = $model->find($data['id']);
  121. $details['name'] = $data['name'];
  122. $details['type'] = $data['type'];
  123. $details['price'] = $data['price'];
  124. $details['status'] = $data['status'];
  125. $details['reward'] = $data['reward'];
  126. $res = $details->save();
  127. if ($res) return Json::successful('修改成功');
  128. return Json::fail('修改失败');
  129. }
  130. /**
  131. * 删除
  132. * @param $id
  133. * @return void
  134. * @throws \Exception
  135. */
  136. public function delete($id)
  137. {
  138. if (!$id) return Json::fail('删除失败');
  139. $model = new model;
  140. $res = model::destroy($id);
  141. if ($res){
  142. return Json::success('删除成功!');
  143. }else{
  144. return Json::fail($model->getErrorInfo());
  145. }
  146. }
  147. /**
  148. * 设置单个产品上架|下架
  149. *
  150. * @return json
  151. */
  152. public function set_show($is_show = '', $id = '')
  153. {
  154. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  155. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  156. if ($res) {
  157. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  158. } else {
  159. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  160. }
  161. }
  162. }