Rescue.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 app\common\model\UserRelation;
  7. use liuniu\UtilService;
  8. use liuniu\WechatTempleService;
  9. use think\Request;
  10. use \app\common\model\Rescue as RescueModel;
  11. class Rescue extends Api
  12. {
  13. protected $noNeedRight = ['*'];
  14. public function index(Request $request)
  15. {
  16. List($page,$limit,$latitude,$longitude) = UtilService::getMore(
  17. [
  18. ['page',1],
  19. ['limit',10],
  20. ['latitude',''],
  21. ['longitude',''],
  22. ],
  23. $request,true
  24. );
  25. if($latitude=='' || $longitude=='') $this->error('请先获取定位');
  26. return $this->success('获取成功',RescueModel::lst($this->cid,$latitude,$longitude,$page,$limit,$this->auth->getUserinfo()['id'],1,1));
  27. }
  28. public function create(Request $request)
  29. {
  30. $where = UtilService::postMore(
  31. [
  32. ['name',''],
  33. ['phone',''],
  34. ['institution_id',0],
  35. ['volunteer_id',0],
  36. ['address',''],
  37. ['latitude',''],
  38. ['longitude',''],
  39. ['certificateimage',''],
  40. ],$request
  41. );
  42. if($where['name']=='')$this->error('姓名不能为空');
  43. if($where['phone']=='')$this->error('电话不能为空');
  44. if($where['address']=='')$this->error('地址信息不能为空');
  45. if($where['certificateimage']=='')$this->error('证书不能为空');
  46. $where['cid'] = $this->cid;
  47. $where['user_id'] = $this->auth->getUserinfo()['id'];
  48. if(RescueModel::where('user_id',$where['user_id'])->where('status','>',-1)->find()) $this->error('已经存,不能重复申请');
  49. if(!RescueModel::create1($where))
  50. {
  51. $this->error(RescueModel::getErrorInfo());
  52. }
  53. $this->success('创建成功');
  54. }
  55. public function applylst(Request $request)
  56. {
  57. return $this->success('获取成功',RescueModel::lst($this->cid,'','',1,10,$this->auth->getUserinfo()['id'],-2));
  58. }
  59. public function sos_create(Request $request)
  60. {
  61. $where = UtilService::postMore(
  62. [
  63. ['mobile',''],
  64. ['address',''],
  65. ['latitude',''],
  66. ['longitude',''],
  67. ['rescuers_id',0],
  68. ['rescuers_user_id',0],
  69. ['from','weixin'],
  70. ['re_url',''],
  71. ],$request
  72. );
  73. if($where['rescuers_id']==0) $this->error('选择救授人员');
  74. if($where['latitude']=='' || $where['longitude']=='') $this->error('请先获取定位');
  75. $where['user_id'] = $this->auth->getUserinfo()['id'];
  76. $where['cid'] = $this->cid;
  77. if(Sos::sos_create($where)) $this->success('创建成功');
  78. $this->error(Sos::getErrorInfo());
  79. }
  80. public function lst(Request $request)
  81. {
  82. $where = UtilService::getMore(
  83. [
  84. ['page',1],
  85. ['limit',10],
  86. ['type',0],
  87. ['status',-3],
  88. ['latitude',''],
  89. ['longitude',''],
  90. ],
  91. $request
  92. );
  93. $where['user_id'] = 0;$where['rescue_id']=0;
  94. if($where['type']==0)
  95. {
  96. $where['user_id']= $this->auth->getUserinfo()['id'];
  97. }
  98. else
  99. {
  100. $where['rescuers_user_id']= $this->auth->getUserinfo()['id'];
  101. }
  102. return $this->success('获取成功',SosBill::lst($where));
  103. }
  104. public function setstatus(Request $request)
  105. {
  106. $where = UtilService::postMore(
  107. [
  108. ['status',1],
  109. ['process_remark',''],
  110. ['from','weixin'],
  111. ['re_url',''],
  112. ],$request
  113. );
  114. $where['processtime'] = time();
  115. $where1 = $where;
  116. unset($where1['from']);
  117. unset($where1['re_url']);
  118. SosBill::where('id',input('id',0))->update($where1);
  119. $info = SosBill::find(input('id',0));
  120. switch (intval($where['status']))
  121. {
  122. case 1:
  123. $temp = WechatTempleService::SUPPAORTER_REPLY;
  124. $res_user = Rescue::where('user_id',$this->auth->getUserinfo()['id'])->find();
  125. $data['first'] = "你发起求救已受理,救员者正在赶来";
  126. $data['keyword1'] = $res_user['phone'];
  127. $data['keyword2'] = $res_user['address'];
  128. $data['keyword3'] = date("Y-m-d H:i:s");
  129. $data['remark'] =$where['process_remark'];
  130. WechatTempleService::sendTemplate($this->cid,UserRelation::userIdToOpenId($info['user_id']),$temp,$data,$where['re_url']);
  131. break;
  132. case 2:
  133. $temp = WechatTempleService::REQUEXST_REFUSE;
  134. $data['first'] = "你发起求救已拒绝";
  135. $data['keyword1'] = $where['process_remark'];
  136. $data['keyword2'] = date("Y-m-d H:i:s");
  137. $data['keyword3'] = "求救";
  138. $data['remark'] ="";
  139. WechatTempleService::sendTemplate($this->cid,UserRelation::userIdToOpenId($info['user_id']),$temp,$data,$where['re_url']);
  140. break;
  141. }
  142. $this->success('处理完成');
  143. }
  144. public function sos_del(Request $request)
  145. {
  146. $id = input('id');
  147. if(SosBill::where('sos_id',$id)->where('status','<',1)->find())
  148. {
  149. SosBill::where('sos_id',$id)->where('status','<',1)->delete();
  150. $this->success('删除成功');
  151. }
  152. $this->error('已删除或已接受');
  153. }
  154. }