DiagnosisService.php 4.5 KB

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