文件
mashangyoujiu/Application/Retail/Model/RiderModel.class.php

186 行
7.3 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Model;
//[1.8.50]
/**
* 骑手信息表
* Class RiderModel
* @package Retail\Model
*/
class RiderModel extends \Common\Model\BaseModel
{
protected $tableName = 'rider_info';
protected $fields = array(
'id', //int(11) NOT NULL AUTO_INCREMENT COMMENT '骑手ID',
'merchant_id', //int(11) NOT NULL DEFAULT '0' COMMENT '商户ID',
'store_id', //int(11) NOT NULL DEFAULT '0' COMMENT '门店ID',
'rider_name', //varchar(50) NOT NULL DEFAULT '' COMMENT '骑手姓名',
'rider_phone', //varchar(20) NOT NULL DEFAULT '' COMMENT '骑手手机号',
'password', //varchar(255) NOT NULL DEFAULT '' COMMENT '登录密码',
'salt', //varchar(32) NOT NULL DEFAULT '' COMMENT '密码盐值',
'rider_avatar', //varchar(255) DEFAULT '' COMMENT '骑手头像',
'id_card', //varchar(18) DEFAULT '' COMMENT '身份证号',
'id_card_front', //varchar(255) DEFAULT '' COMMENT '身份证正面照片',
'id_card_back', //varchar(255) DEFAULT '' COMMENT '身份证反面照片',
'health_certificate', //varchar(255) DEFAULT '' COMMENT '健康证照片',
'emergency_contact', //varchar(50) DEFAULT '' COMMENT '紧急联系人',
'emergency_phone', //varchar(20) DEFAULT '' COMMENT '紧急联系人电话',
'work_status', //tinyint(1) NOT NULL DEFAULT '1' COMMENT '工作状态:1-在职,2-离职',
'auth_status', //tinyint(1) NOT NULL DEFAULT '0' COMMENT '认证状态:0-未认证,1-认证中,2-已认证,3-认证失败',
'health_status', //tinyint(1) NOT NULL DEFAULT '0' COMMENT '健康证状态:0-未上传,1-审核中,2-已通过,3-已过期',
'balance', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '账户余额',
'total_orders', //int(11) NOT NULL DEFAULT '0' COMMENT '总订单数',
'total_income', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '总收入',
'today_orders', //int(11) NOT NULL DEFAULT '0' COMMENT '今日订单数',
'today_income', //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '今日收入',
'rating', //decimal(3,2) NOT NULL DEFAULT '5.00' COMMENT '服务评分',
'on_time_rate', //decimal(5,2) NOT NULL DEFAULT '100.00' COMMENT '准时率',
'last_location_lat', //decimal(10,6) DEFAULT NULL COMMENT '最后位置纬度',
'last_location_lng', //decimal(10,6) DEFAULT NULL COMMENT '最后位置经度',
'last_location_time', //int(11) DEFAULT NULL COMMENT '最后位置更新时间',
'register_time', //int(11) NOT NULL DEFAULT '0' COMMENT '注册时间',
'last_login_time', //int(11) DEFAULT NULL COMMENT '最后登录时间',
'status', //tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:1-正常,2-禁用,3-删除',
'add_time', //varchar(20) NOT NULL DEFAULT '' COMMENT '注册时间',
);
/**
* 根据手机号获取骑手信息
* @param string $phone 手机号
* @param int $merchant_id 商户ID
* @return array|null
*/
public function getRiderByPhone($phone, $merchant_id = 0)
{
$map = array(
'rider_phone' => $phone,
'status' => array('neq', 3)
);
if ($merchant_id > 0) {
$map['merchant_id'] = $merchant_id;
}
return $this->getFind($map);
}
/**
* 获取骑手列表
* @param array $map 查询条件
* @param string $field 查询字段
* @param string $order 排序
* @param string $limit 分页
* @return array
*/
public function getRiderList($map, $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 int $rider_id 骑手ID
* @param int $auth_status 认证状态
* @return bool
*/
public function updateAuthStatus($rider_id, $auth_status)
{
$map = array('id' => $rider_id);
$data = array(
'auth_status' => $auth_status
);
return $this->updateOrder($map, $data);
}
/**
* 更新骑手健康证状态
* @param int $rider_id 骑手ID
* @param int $health_status 健康证状态
* @return bool
*/
public function updateHealthStatus($rider_id, $health_status)
{
$map = array('id' => $rider_id);
$data = array(
'health_status' => $health_status
);
return $this->updateOrder($map, $data);
}
/**
* 重置骑手密码
* @param int $rider_id 骑手ID
* @param string $new_password 新密码
* @param string $salt 盐值
* @return bool
*/
public function resetPassword($rider_id, $new_password, $salt)
{
$map = array('id' => $rider_id);
$data = array(
'password' => $new_password,
'salt' => $salt
);
return $this->updateOrder($map, $data);
}
/**
* 更新骑手位置信息
* @param int $rider_id 骑手ID
* @param float $lat 纬度
* @param float $lng 经度
* @return bool
*/
public function updateLocation($rider_id, $lat, $lng)
{
$map = array('id' => $rider_id);
$data = array(
'last_location_lat' => $lat,
'last_location_lng' => $lng,
'last_location_time' => time()
);
return $this->updateOrder($map, $data);
}
/**
* 更新骑手统计数据
* @param int $rider_id 骑手ID
* @param array $stats 统计数据
* @return bool
*/
public function updateStats($rider_id, $stats)
{
$map = array('id' => $rider_id);
$data = $stats;
return $this->updateOrder($map, $data);
}
/**
* 获取商户下的骑手统计
* @param int $merchant_id 商户ID
* @param int $store_id 门店ID(可选)
* @return array
*/
public function getRiderStats($merchant_id, $store_id = 0)
{
$map = array(
'merchant_id' => $merchant_id,
'status' => array('neq', 3)
);
if ($store_id > 0) {
$map['store_id'] = $store_id;
}
$stats = array();
$stats['total'] = $this->getCount($map);
$stats['working'] = $this->getCount(array_merge($map, array('work_status' => 1)));
$stats['certified'] = $this->getCount(array_merge($map, array('auth_status' => 2)));
$stats['pending_auth'] = $this->getCount(array_merge($map, array('auth_status' => 1)));
return $stats;
}
}