12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\common\model;
- use liuniu\BaseModel;
- use think\Exception;
- use think\Model;
- class Sos extends BaseModel
- {
- // 表名
- protected $name = 'sos';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'status_text'
- ];
- public function getStatusList()
- {
- return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public static function sos_create($where)
- {
- self::beginTrans();
- try {
- if(SosBill::where('id', $where['user_id'])->where('rescuers_id',$where['rescuers_id'])->whereTime('createtime',"today")->find()) return self::setErrorInfo('已求救,不用重复发起!');
- $res = self::create($where);
- $user_phone = User::where('id', $where['user_id'])->value('mobile');
- $rescue_phone = User::where('id', $where['rescuers_user_id'])->value('mobile');
- $rescuers_id = Rescue::where('uid',$where['rescuers_user_id'])->value('id');
- $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']);
- //tudo 模板信息
- if($res && $res1)
- {
- self::commitTrans();
- }
- }catch (Exception $e)
- {
- return self::setErrorInfo($e->getMessage(),true);
- }
- return $res;
- }
- }
|