DiagnosisApply.php 4.9 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 app\admin\model\user\User;
  10. use crmeb\services\{ExpressService,
  11. JsonService,
  12. JsonService as Json,
  13. MiniProgramService,
  14. WechatService,
  15. FormBuilder as Form,
  16. CacheService,
  17. UtilService as Util};
  18. use think\facade\Route as Url;
  19. use think\facade\Validate;
  20. Use app\admin\model\diagnosis\DiagnosisApply as model;
  21. /**
  22. * 订单管理控制器 同一个订单表放在一个控制器
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class DiagnosisApply extends AuthController
  27. {
  28. /**
  29. * @return mixed
  30. */
  31. public function index()
  32. {
  33. return $this->fetch();
  34. }
  35. public function list()
  36. {
  37. $where = Util::getMore([
  38. ['page', 1],
  39. ['limit', 20],
  40. ['name', ''],
  41. ['role', ''],
  42. ['type', ''],
  43. ['gc', ''],
  44. ]);
  45. return Json::successlayui(model::list($where));
  46. }
  47. /**
  48. * 显示创建资源表单页.
  49. *
  50. * @return \think\Response
  51. */
  52. public function create($id = 0)
  53. {
  54. $f = [];
  55. $f[] = Form::input('name', '名称')->required();
  56. $f[] = Form::select('type', '选择类型', '')->options([
  57. ['value' => 1, 'label' => '陪诊'],
  58. ['value' => 2, 'label' => '代办'],
  59. ])->filterable(true)->required();
  60. $f[] = Form::input('price', '金额')->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. ]);
  75. $res = $model->save($data);
  76. if ($res) return Json::successful('添加成功');
  77. return Json::fail('添加失败');
  78. }
  79. /**
  80. * 显示创建资源表单页.
  81. *
  82. * @return \think\Response
  83. */
  84. public function edit($id = 0)
  85. {
  86. $data = model::find($id);
  87. $f = [];
  88. $f[] = Form::textarea('remarks', '备注');
  89. $f[] = Form::radio('status', '状态', 1)->options([['value' => -1, 'label' => '拒绝'], ['value' => 1, 'label' => '通过']]);
  90. $f[] = Form::hidden('id', $id);
  91. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  92. $this->assign(compact('form'));
  93. return $this->fetch('public/form-builder');
  94. }
  95. /**
  96. * 修改
  97. * @return void
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\DbException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. */
  102. public function update()
  103. {
  104. $model = new model;
  105. $data = Util::postMore([
  106. 'remarks',
  107. 'status',
  108. 'id'
  109. ]);
  110. $details = $model->find($data['id']);
  111. $user = User::where('uid', $details['uid'])->find();
  112. if ($data['status'] == -1){
  113. if (empty($data['remarks'])){
  114. return Json::fail('请填入备注');
  115. }
  116. $details['remarks'] = $data['remarks'];
  117. }else{
  118. if ($user['is_receiver'] == 1){
  119. return Json::successful('用户已成为接单员');
  120. }
  121. $user['is_receiver'] = 1;
  122. $user->save();
  123. }
  124. $details['status'] = $data['status'];
  125. $res = $details->save();
  126. if ($res) return Json::successful('成功');
  127. return Json::fail('失败');
  128. }
  129. /**
  130. * 删除
  131. * @param $id
  132. * @return void
  133. * @throws \Exception
  134. */
  135. public function delete($id)
  136. {
  137. if (!$id) return Json::fail('删除失败');
  138. $model = new model;
  139. $res = model::destroy($id);
  140. if ($res){
  141. return Json::success('删除成功!');
  142. }else{
  143. return Json::fail($model->getErrorInfo());
  144. }
  145. }
  146. /**
  147. * 设置单个产品上架|下架
  148. *
  149. * @return json
  150. */
  151. public function set_show($is_show = '', $id = '')
  152. {
  153. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  154. $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
  155. if ($res) {
  156. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  157. } else {
  158. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  159. }
  160. }
  161. public function card($id)
  162. {
  163. $data = model::find($id);
  164. $images = json_decode($data['images']);
  165. $this->assign('images', $images);
  166. return $this->fetch();
  167. }
  168. }