链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

102 lines
2.5 KiB

<?php
namespace App\Models\v3;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class LanzuEmployees extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
const TABLE_NAME = 'lanzu_employees';
protected $table = 'lanzu_employees';
protected $dateFormat = 'U';
/* 查询记录数 limit */
protected $perPage = 10;
protected $casts = [
'position'=>'array',
];
public static $_TYPE= [''];
public static $_STATUS = [-1=>'离职',0=>'禁用',1=>'正常'];
protected $appends = [
'type_text',
'status_text'
];
public function getTypeTextAttribute($value)
{
$value = $value ? $value : $this->type;
return isset(self::$_TYPE[$value]) ? self::$_TYPE[$value] : '';
}
public function getStatusTextAttribute($value)
{
$value = $value ? $value : $this->status;
return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
}
/**
* 根据id获取单条信息
* @param int $id
* @param string $field
* @return string
*/
public static function getInfo($id,$field = '*')
{
return self::select($field)->find($id);
}
/**
* 获取数组
* id为键
* @return array
*/
public static function getArray($where = [], $options = [])
{
$model = self::whereNull('deleted_at');
if(!empty($where)){
$model->where($where);
}
$list = $model->pluck('id','user_id')->toArray();
if(!empty($options)){
$new = array_merge($options,$list);
return array_flip($new);
}else{
return array_flip($list);
}
}
public static function getHorseman($marketId=null)
{
if ($marketId){
$rows = self::where('market_id',$marketId)
->where('position','REGEXP','"29"')
->where('status',1)
->get();
}else{
$rows = self::where('position','REGEXP','"29"')->where('status',1)->get();
}
$item = [];
if ($rows){
foreach ($rows as $row) {
$item[$row->id] = $row->name;
}
}
return $item;
}
public static function getName($hid=null)
{
//获取骑手名称
if ($hid){
$horseman = self::find($hid);
if ($horseman){
return $horseman->name;
}
}
return '--';
}
}