Sos.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\common\model;
  3. use liuniu\BaseModel;
  4. use think\Exception;
  5. use think\Model;
  6. class Sos extends BaseModel
  7. {
  8. // 表名
  9. protected $name = 'sos';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = false;
  16. // 追加属性
  17. protected $append = [
  18. 'status_text'
  19. ];
  20. public function getStatusList()
  21. {
  22. return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
  23. }
  24. public function getStatusTextAttr($value, $data)
  25. {
  26. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  27. $list = $this->getStatusList();
  28. return isset($list[$value]) ? $list[$value] : '';
  29. }
  30. public static function sos_create($where)
  31. {
  32. self::beginTrans();
  33. try {
  34. if(SosBill::where('id', $where['user_id'])->where('rescuers_id',$where['rescuers_id'])->whereTime('createtime',"today")->find()) return self::setErrorInfo('已求救,不用重复发起!');
  35. $res = self::create($where);
  36. $user_phone = User::where('id', $where['user_id'])->value('mobile');
  37. $rescue_phone = User::where('id', $where['rescuers_user_id'])->value('mobile');
  38. $rescuers_id = Rescue::where('uid',$where['rescuers_user_id'])->value('id');
  39. $res1 = SosBill::income($where['cid'], $where['user_id'], $res['id'], $rescuers_id,$where['rescuers_user_id'], $where['latitude'], $where['longitude'], $user_phone, $rescue_phone,$where['address']);
  40. //tudo 模板信息
  41. if($res && $res1)
  42. {
  43. self::commitTrans();
  44. }
  45. }catch (Exception $e)
  46. {
  47. return self::setErrorInfo($e->getMessage(),true);
  48. }
  49. return $res;
  50. }
  51. }