Rescue.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. $this->error(RescueModel::getErrorInfo());
  51. }
  52. $this->success('创建成功');
  53. }
  54. public function applylst(Request $request)
  55. {
  56. return $this->success('获取成功', RescueModel::lst($this->cid, '', '', 1, 10, $this->auth->getUserinfo()['id'], -2));
  57. }
  58. public function sos_create(Request $request)
  59. {
  60. $where = UtilService::postMore(
  61. [
  62. ['mobile', ''],
  63. ['address', ''],
  64. ['latitude', ''],
  65. ['longitude', ''],
  66. ['rescuers_id', 0],
  67. ['rescuers_user_id', 0],
  68. ['from', 'weixin'],
  69. ['re_url', ''],
  70. ], $request
  71. );
  72. if ($where['rescuers_id'] == 0) $this->error('选择救授人员');
  73. if ($where['latitude'] == '' || $where['longitude'] == '') $this->error('请先获取定位');
  74. $where['user_id'] = $this->auth->getUserinfo()['id'];
  75. $where['cid'] = $this->cid;
  76. if (Sos::sos_create($where)) $this->success('创建成功');
  77. $this->error(Sos::getErrorInfo());
  78. }
  79. public function lst(Request $request)
  80. {
  81. $where = UtilService::getMore(
  82. [
  83. ['page', 1],
  84. ['limit', 10],
  85. ['type', 0],
  86. ['status', -3],
  87. ['latitude', ''],
  88. ['longitude', ''],
  89. ],
  90. $request
  91. );
  92. $where['user_id'] = 0;
  93. $where['rescue_id'] = 0;
  94. if ($where['type'] == 0) {
  95. $where['user_id'] = $this->auth->getUserinfo()['id'];
  96. } else {
  97. $where['rescuers_user_id'] = $this->auth->getUserinfo()['id'];
  98. }
  99. return $this->success('获取成功', SosBill::lst($where));
  100. }
  101. public function setstatus(Request $request)
  102. {
  103. $where = UtilService::postMore(
  104. [
  105. ['status', 1],
  106. ['process_remark', ''],
  107. ['from', 'weixin'],
  108. ['re_url', ''],
  109. ], $request
  110. );
  111. $where['processtime'] = time();
  112. $where1 = $where;
  113. unset($where1['from']);
  114. unset($where1['re_url']);
  115. SosBill::where('id', input('id', 0))->update($where1);
  116. $info = SosBill::find(input('id', 0));
  117. switch (intval($where['status'])) {
  118. case 1:
  119. $temp = WechatTempleService::SUPPAORTER_REPLY;
  120. $res_user = RescueModel::where('user_id', $this->auth->getUserinfo()['id'])->find();
  121. $data['first'] = "你发起求救已受理,救员者正在赶来";
  122. $data['keyword1'] = $res_user['phone'];
  123. $data['keyword2'] = $res_user['address'];
  124. $data['keyword3'] = date("Y-m-d H:i:s");
  125. $data['remark'] = $where['process_remark'];
  126. $rs = WechatTempleService::sendTemplate($this->cid, UserRelation::userIdToOpenId($info['user_id']), $temp, $data, $where['re_url']);
  127. break;
  128. case -1:
  129. $temp = WechatTempleService::REQUEXST_REFUSE;
  130. $data['first'] = "你发起求救已拒绝";
  131. $data['keyword1'] = $where['process_remark'];
  132. $data['keyword2'] = date("Y-m-d H:i:s");
  133. $data['keyword3'] = "求救";
  134. $data['remark'] = "";
  135. $rs = WechatTempleService::sendTemplate($this->cid, UserRelation::userIdToOpenId($info['user_id']), $temp, $data, $where['re_url']);
  136. break;
  137. }
  138. $this->success('处理完成');
  139. }
  140. public function sos_del(Request $request)
  141. {
  142. $id = input('id');
  143. if (SosBill::where('sos_id', $id)->where('status', '<', 1)->find()) {
  144. SosBill::where('sos_id', $id)->where('status', '<', 1)->delete();
  145. $this->success('删除成功');
  146. }
  147. $this->error('已删除或已接受');
  148. }
  149. }