$userRunAll = UserRun::field('id,user_id,run_step')
->where('add_time','=',$today_start)
->order('run_step desc')
->select();
$randing_array = array_column($userRunAll->toArray(),'user_id');
$randing = array_search($user_id,$randing_array) +1;
<?php
/**
* Created by PhpStorm.
* User: 12155
* Date: 2019/4/24
* Time: 16:34
*/
namespace app\userapi\service;
use app\exception\ParameException;
class RegularExpression
{
// 常见的正则表达式
private $validate = [
'mobile' => '/^(1)[0-9]{10}$/',
'date' => '/^2[0-9]{3}-[0-9]{2}-[0-9]{2}$/',
'datetime' => '/^2[0-9]{3}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}(:[0-9]{2})?$/',
'http' => '/^.\/upload\/.+$/',
'require' => '/.+/',
'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
'currency' => '/^\d+(\.\d+)?$/',
'number' => '/^\d+$/',
'zip' => '/^\d{6}$/',
'integer' => '/^[-\+]?\d+$/',
'double' => '/^[-\+]?\d+(\.\d+)?$/',
'english' => '/^[A-Za-z]+$/',
'qq' => '/^\d{5,11}$/',
'ip' => '/^\d+\.\d+\.\d+\.\d+$/'
];
/**
* 检查是否符合规范 true false
* @author:dsp
* @param $pattern
* @param $subject
* @return string
* @date:2019/2/25 15:00
*/
private function ischeck($pattern, $subject)
{
$patternStatus = array_key_exists(strtolower($pattern),$this->validate);
if ($patternStatus) {
// 判断存在自定义的数组中时
$this->isMatch = preg_match($this->validate[$pattern], $subject) === 1?true:false;
} else {
$this->isMatch = false;
}
return $this->isMatch;
}
/**
* @author:dsp
* @param $pattern
* @param $subject
* @return bool
* @date:2019/2/25 15:36
*/
public function isvalidate($pattern, $subject)
{
return $this->ischeck($pattern, $subject);
}
/**
* 检测手机号是否合法
* @author:dsp
* @param $subject
* @param string $message
* @return bool
* @throws ParameException
* @date:2019/2/26 11:48
*/
public function isMobile($subject, $message = '抱歉,手机号格式错误!')
{
// 去除字符串两边字符
$subject = trim($subject);
$status = $this->ischeck('mobile',$subject);
if (!$status) {
throw new ParameException($message);
}
return $subject;
}
/**
* 验证是否为日期格式
* @author:dsp
* @param $subject
* @return bool
* @throws ParameException
* @date:2019/2/27 17:20
*/
public function isDate($subject)
{
$status = $this->ischeck('date',$subject);
if (!$status) {
throw new ParameException('抱歉,日期格式错误!');
}
return $subject;
}
/**
* 验证是否为日期时间格式 2019-02-27 17:30:06
* @author:dsp
* @param $subject
* @param string $errorMsg
* @return bool
* @throws ParameException
* @date:2019/2/27 17:19
*/
public function isDateTime($subject, $errorMsg = '抱歉,日期时间格式错误!')
{
$status = $this->ischeck('datetime',$subject);
if (!$status) {
throw new ParameException($errorMsg);
}
return $subject;
}
/**
* 验证邮箱格式是否输入正确
* @author:dsp
* @param $subject
* @return mixed
* @throws ParameException
* @date:2019/2/27 18:14
*/
public function isEmail($subject)
{
$status = $this->ischeck('email',$subject);
if (!$status) {
throw new ParameException('抱歉,您输入的邮箱格式错误!');
}
return $subject;
}
/**
* 验证ip地址
* @author:dsp
* @param $subject
* @return mixed
* @throws ParameException
* @date:2019/2/27 18:18
*/
public function isIP($subject)
{
$status = $this->ischeck('ip',$subject);
if (!$status) {
throw new ParameException('抱歉,您的ip地址错误!');
}
return $subject;
}
/**
* @return bool
* @author: deng (2019/4/24 16:38)
*/
public function isHttp($subject)
{
$status = $this->ischeck('http',$subject);
return $status;
}
}