Rescue.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Sos;
  5. use app\common\model\SosBill;
  6. use liuniu\UtilService;
  7. use think\Request;
  8. use \app\common\model\Rescue as RescueModel;
  9. class Rescue extends Api
  10. {
  11. protected $noNeedRight = ['*'];
  12. public function index(Request $request)
  13. {
  14. List($page,$limit,$latitude,$longitude) = UtilService::getMore(
  15. [
  16. ['page',1],
  17. ['limit',10],
  18. ['latitude',''],
  19. ['longitude',''],
  20. ],
  21. $request,true
  22. );
  23. if($latitude=='' || $longitude=='') $this->error('请先获取定位');
  24. return $this->success('获取成功',RescueModel::lst($this->cid,$latitude,$longitude,$page,$limit,$this->auth->getUserinfo()['id'],1,1));
  25. }
  26. public function create(Request $request)
  27. {
  28. $where = UtilService::postMore(
  29. [
  30. ['name',''],
  31. ['phone',''],
  32. ['institution_id',0],
  33. ['volunteer_id',0],
  34. ['address',''],
  35. ['latitude',''],
  36. ['longitude',''],
  37. ['certificateimage',''],
  38. ],$request
  39. );
  40. if($where['name']=='')$this->error('姓名不能为空');
  41. if($where['phone']=='')$this->error('电话不能为空');
  42. if($where['address']=='')$this->error('地址信息不能为空');
  43. if($where['certificateimage']=='')$this->error('证书不能为空');
  44. $where['cid'] = $this->cid;
  45. $where['user_id'] = $this->auth->getUserinfo()['id'];
  46. if(RescueModel::where('user_id',$where['user_id'])->where('status','>',-1)->find()) $this->error('已经存,不能重复申请');
  47. if(!RescueModel::create1($where))
  48. {
  49. $this->error(RescueModel::getErrorInfo());
  50. }
  51. $this->success('创建成功');
  52. }
  53. public function applylst(Request $request)
  54. {
  55. return $this->success('获取成功',RescueModel::lst($this->cid,'','',1,10,$this->auth->getUserinfo()['id'],-2));
  56. }
  57. public function sos_create(Request $request)
  58. {
  59. $where = UtilService::postMore(
  60. [
  61. ['mobile',''],
  62. ['address',''],
  63. ['latitude',''],
  64. ['longitude',''],
  65. ['rescuers_id',0],
  66. ['rescuers_user_id',0],
  67. ],$request
  68. );
  69. if($where['rescuers_id']==0) $this->error('选择救授人员');
  70. if($where['latitude']=='' || $where['longitude']=='') $this->error('请先获取定位');
  71. $where['user_id'] = $this->auth->getUserinfo()['id'];
  72. $where['cid'] = $this->cid;
  73. if(Sos::sos_create($where)) $this->success('创建成功');
  74. $this->error(Sos::getErrorInfo());
  75. }
  76. public function lst(Request $request)
  77. {
  78. $where = UtilService::getMore(
  79. [
  80. ['page',1],
  81. ['limit',10],
  82. ['type',0],
  83. ['status',-3],
  84. ['latitude',''],
  85. ['longitude',''],
  86. ],
  87. $request
  88. );
  89. $where['user_id'] = 0;$where['rescue_id']=0;
  90. if($where['type']==0)
  91. {
  92. $where['user_id']= $this->auth->getUserinfo()['id'];
  93. }
  94. else
  95. {
  96. $where['rescuers_user_id']= $this->auth->getUserinfo()['id'];
  97. }
  98. return $this->success('获取成功',SosBill::lst($where));
  99. }
  100. public function setstatus(Request $request)
  101. {
  102. $where = UtilService::postMore(
  103. [
  104. ['status',1],
  105. ['process_remark',''],
  106. ],$request
  107. );
  108. $where['processtime'] = time();
  109. SosBill::where('id',input('id',0))->update($where);
  110. $this->success('处理完成');
  111. }
  112. public function sos_del(Request $request)
  113. {
  114. $id = input('id');
  115. if(SosBill::where('sos_id',$id)->where('status','<',1)->find())
  116. {
  117. SosBill::where('sos_id',$id)->where('status','<',1)->delete();
  118. $this->success('删除成功');
  119. }
  120. $this->error('已删除或已接受');
  121. }
  122. }