DiagnosisService.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\DiagnosisService as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class DiagnosisService 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::input('price', '金额')->required();
  56. $f[] = Form::radio('status', '状态', 1)->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  57. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  58. $this->assign(compact('form'));
  59. return $this->fetch('public/form-builder');
  60. }
  61. public function save()
  62. {
  63. $model = new model;
  64. $data = Util::postMore([
  65. 'name',
  66. 'type',
  67. 'price',
  68. 'status',
  69. ]);
  70. $res = $model->save($data);
  71. if ($res) return Json::successful('添加成功');
  72. return Json::fail('添加失败');
  73. }
  74. /**
  75. * 显示创建资源表单页.
  76. *
  77. * @return \think\Response
  78. */
  79. public function edit($id = 0)
  80. {
  81. $data = model::find($id);
  82. $f = [];
  83. $f[] = Form::input('name', '分类名称', $data['name'])->required();
  84. $f[] = Form::input('price', '金额', $data['price'])->required();
  85. $f[] = Form::radio('status', '状态', (string)$data['status'])->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
  86. $f[] = Form::hidden('id', $id);
  87. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  88. $this->assign(compact('form'));
  89. return $this->fetch('public/form-builder');
  90. }
  91. /**
  92. * 修改
  93. * @return void
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\DbException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. */
  98. public function update()
  99. {
  100. $model = new model;
  101. $data = Util::postMore([
  102. 'name',
  103. 'type',
  104. 'price',
  105. 'status',
  106. 'id'
  107. ]);
  108. $details = $model->find($data['id']);
  109. $details['name'] = $data['name'];
  110. $details['type'] = $data['type'];
  111. $details['price'] = $data['price'];
  112. $details['status'] = $data['status'];
  113. $res = $details->save();
  114. if ($res) return Json::successful('修改成功');
  115. return Json::fail('修改失败');
  116. }
  117. /**
  118. * 删除
  119. * @param $id
  120. * @return void
  121. * @throws \Exception
  122. */
  123. public function delete($id)
  124. {
  125. if (!$id) return Json::fail('删除失败');
  126. $model = new model;
  127. $res = model::destroy($id);
  128. if ($res){
  129. return Json::success('删除成功!');
  130. }else{
  131. return Json::fail($model->getErrorInfo());
  132. }
  133. }
  134. /**
  135. * 设置单个产品上架|下架
  136. *
  137. * @return json
  138. */
  139. public function set_show($is_show = '', $id = '')
  140. {
  141. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  142. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  143. if ($res) {
  144. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  145. } else {
  146. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  147. }
  148. }
  149. }