文件
mashangyoujiu/Application/Common/Model/RiderInfoModel.class.php

143 行
3.8 KiB
PHP

<?php
namespace Common\Model;
use Common\Model\BaseModel;
/**
* 骑手信息模型
*/
class RiderInfoModel extends BaseModel {
protected $tableName = 'rider_info';
/**
* 根据手机号获取骑手信息
* @param string $phone 手机号
* @return array|null
*/
public function getRiderByPhone($phone) {
return $this->where(['phone' => $phone])->find();
}
/**
* 获取骑手列表
* @param array $map 查询条件
* @param string $field 查询字段
* @param string $order 排序
* @param string $limit 分页
* @return array
*/
public function getRiderList($map = array(), $field = '*', $order = 'id desc', $limit = '')
{
if ($limit) {
return $this->field($field)->where($map)->order($order)->limit($limit)->select();
} else {
return $this->field($field)->where($map)->order($order)->select();
}
}
/**
* 获取记录列表
* @param array $where 查询条件
* @param string $field 查询字段
* @param string $order 排序
* @param string $limit 分页
* @return array
*/
public function getList($where = array(), $field = '*', $order = 'id desc', $limit = '') {
if ($limit) {
return $this->field($field)->where($where)->order($order)->limit($limit)->select();
} else {
return $this->field($field)->where($where)->order($order)->select();
}
}
/**
* 获取记录数量
* @param array $where 查询条件
* @return int
*/
public function getCount($where = array()) {
return $this->where($where)->count();
}
/**
* 更新骑手认证状态
* @param int $riderId 骑手ID
* @param int $status 认证状态
* @return bool
*/
public function updateAuthStatus($riderId, $status) {
return $this->where(['id' => $riderId])->save(['auth_status' => $status]);
}
/**
* 更新骑手健康状态
* @param int $riderId 骑手ID
* @param int $status 健康状态
* @return bool
*/
public function updateHealthStatus($riderId, $status) {
return $this->where(['id' => $riderId])->save(['health_status' => $status]);
}
/**
* 重置骑手密码
* @param int $riderId 骑手ID
* @param string $password 新密码
* @return bool
*/
public function resetPassword($riderId, $password) {
return $this->where(['id' => $riderId])->save(['password' => md5($password)]);
}
/**
* 更新骑手位置
* @param int $riderId 骑手ID
* @param float $lat 纬度
* @param float $lng 经度
* @return bool
*/
public function updateLocation($riderId, $lat, $lng) {
return $this->where(['id' => $riderId])->save([
'last_location_lat' => $lat,
'last_location_lng' => $lng,
'last_location_time' => date('Y-m-d H:i:s')
]);
}
/**
* 更新骑手统计信息
* @param int $riderId 骑手ID
* @param array $stats 统计数据
* @return bool
*/
public function updateStats($riderId, $stats) {
return $this->where(['id' => $riderId])->save($stats);
}
/**
* 更新骑手信息
* @param array $where 查询条件
* @param array $data 更新数据
* @return bool
*/
public function updateRider($where, $data) {
return $this->where($where)->save($data);
}
/**
* 获取骑手统计信息
* @param int $riderId 骑手ID
* @return array
*/
public function getRiderStats($riderId)
{
return array(
'total_orders' => 0,
'completed_orders' => 0,
'total_distance' => 0,
'total_earnings' => 0,
'avg_rating' => 0
);
}
}