activateSync

This commit is contained in:
邓皓元 2018-11-09 19:18:37 +08:00
parent e02e0e1017
commit 677a253111
16 changed files with 413 additions and 1680 deletions

View File

@ -3,6 +3,9 @@
namespace App\Domains\Real\Commands\Sync;
use Carbon\Carbon;
use App\Models\Card;
use MongoDB\BSON\UTCDateTime;
use Illuminate\Support\Facades\DB;
class ActivateSync extends Command
{
@ -13,5 +16,23 @@ class ActivateSync extends Command
public function handle()
{
$datetime = $this->getDateTime();
$starttime = new UTCDateTime($datetime->copy()->startOfDay()->startOfMonth()->timestamp * 1000);
$endtime = new UTCDateTime($datetime->copy()->endOfDay()->endOfMonth()->timestamp * 1000);
$res = DB::connection('mongo')->table('tblCard')->select(['cNo', 'saDate'])
->where('pNo', 'No00000000768')
->where('isDel', '<>', 1)
->whereBetween('saDate', [$starttime, $endtime])->get();
$list = $res->map(function ($item) {
return [
'sim' => $item['cNo'],
'activate_at' => $item['saDate']->toDateTime()->format('Y-m-d H:i:s'),
];
})->toArray();
foreach (array_chunk($list, 10000) as $data) {
Card::updateBatch($data, 'sim');
}
}
}

View File

@ -135,6 +135,7 @@ class OrderBaseSync extends Command
foreach ($cardChunks as $cardChunk) {
echo '.';
$res = DB::connection('mongo')->table('tblCard')->select(['cNo', 'bNo', 'sPCode', 'iccid', 'imsi', 'soDate', 'comId', 'oType', 'jBatchNo'])
->where('isDel', '<>', 1)
->whereIn('cNo', array_pluck($cardChunk, 'sim'))->get()->toArray();
$card_details = array_merge($card_details, $res);

810
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,12 @@
<?= '<?php' ?>
<?php
/**
* @var \Barryvdh\LaravelIdeHelper\Alias[][] $namespaces_by_alias_ns
* @var \Barryvdh\LaravelIdeHelper\Alias[][] $namespaces_by_extends_ns
* @var bool $include_fluent
* @var string $helpers
*/
?>
// @formatter:off
@ -28,7 +36,7 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
//Method inherited from <?= $method->getDeclaringClass() ?>
<?php endif; ?>
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
}
<?php endforeach; ?>
}
@ -50,7 +58,7 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
//Method inherited from <?= $method->getDeclaringClass() ?>
<?php endif; ?>
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
}
<?php endforeach; ?>
<?php endif; ?>}

View File

@ -171,7 +171,7 @@ class Alias
/**
* Get the methods found by this Alias
*
* @return array
* @return array|Method[]
*/
public function getMethods()
{
@ -310,7 +310,7 @@ class Alias
$method = new \ReflectionMethod($className, $name);
$class = new \ReflectionClass($className);
if (!in_array($method->name, $this->usedMethods)) {
if (!in_array($magic, $this->usedMethods)) {
if ($class !== $this->root) {
$this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces);
}

View File

@ -444,6 +444,9 @@ class ModelsCommand extends Command
array_shift($args);
$this->setMethod($name, '\Illuminate\Database\Eloquent\Builder|\\' . $reflection->class, $args);
}
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
$reflection = new \ReflectionClass($model);
$this->setMethod($method, '\Illuminate\Database\Eloquent\Builder|\\' . $reflection->getName());
} elseif (!method_exists('Illuminate\Database\Eloquent\Model', $method)
&& !Str::startsWith($method, 'get')
) {

View File

@ -272,9 +272,13 @@ class Generator
$facades = array_merge($facades, $this->config->get('app.aliases', []));
// Only return the ones that actually exist
return array_filter($facades, function ($alias) {
return class_exists($alias);
});
return array_filter(
$facades,
function ($alias) {
return class_exists($alias);
},
ARRAY_FILTER_USE_KEY
);
}
/**

View File

@ -17,36 +17,30 @@ class Macro extends Method
* @param array $interfaces
*/
public function __construct(
\ReflectionFunctionAbstract $method,
$method,
$alias,
$class,
$methodName = null,
$interfaces = array()
) {
$this->method = $method;
$this->interfaces = $interfaces;
$this->name = $methodName ?: $method->name;
$this->namespace = $class->getNamespaceName();
parent::__construct($method, $alias, $class, $methodName, $interfaces);
}
//Create a DocBlock and serializer instance
/**
* @param \ReflectionFunctionAbstract $method
*/
protected function initPhpDoc($method)
{
$this->phpdoc = new DocBlock($method);
}
//Normalize the description and inherit the docs from parents/interfaces
try {
$this->normalizeParams($this->phpdoc);
$this->normalizeReturn($this->phpdoc);
$this->normalizeDescription($this->phpdoc);
} catch (\Exception $e) {
}
//Get the parameters, including formatted default values
$this->getParameters($method);
//Make the method static
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
//Reference the 'real' function in the declaringclass
/**
* @param \ReflectionFunctionAbstract $method
* @param \ReflectionClass $class
*/
protected function initClassDefinedProperties($method, \ReflectionClass $class)
{
$this->namespace = $class->getNamespaceName();
$this->declaringClassName = '\\' . ltrim($class->name, '\\');
$this->root = '\\' . ltrim($class->getName(), '\\');
}
}

View File

@ -26,29 +26,32 @@ class Method
protected $method;
protected $output = '';
protected $declaringClassName;
protected $name;
protected $namespace;
protected $params = array();
protected $params_with_default = array();
protected $interfaces = array();
protected $real_name;
protected $return = null;
/**
* @param \ReflectionMethod $method
* @param \ReflectionMethod|\ReflectionFunctionAbstract $method
* @param string $alias
* @param \ReflectionClass $class
* @param string|null $methodName
* @param array $interfaces
*/
public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array())
public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
{
$this->method = $method;
$this->interfaces = $interfaces;
$this->name = $methodName ?: $method->name;
$this->namespace = $method->getDeclaringClass()->getNamespaceName();
$this->real_name = $method->name;
$this->initClassDefinedProperties($method, $class);
//Create a DocBlock and serializer instance
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
$this->initPhpDoc($method);
//Normalize the description and inherit the docs from parents/interfaces
try {
@ -64,12 +67,29 @@ class Method
//Make the method static
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
//Reference the 'real' function in the declaringclass
$declaringClass = $method->getDeclaringClass();
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
//Reference the 'real' function in the declaring class
$this->root = '\\' . ltrim($class->getName(), '\\');
}
/**
* @param \ReflectionMethod $method
*/
protected function initPhpDoc($method)
{
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
}
/**
* @param \ReflectionMethod $method
* @param \ReflectionClass $class
*/
protected function initClassDefinedProperties($method, \ReflectionClass $class)
{
$declaringClass = $method->getDeclaringClass();
$this->namespace = $declaringClass->getNamespaceName();
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
}
/**
* Get the class wherein the function resides
*
@ -112,6 +132,16 @@ class Method
return $this->name;
}
/**
* Get the real method name
*
* @return string
*/
public function getRealName()
{
return $this->real_name;
}
/**
* Get the parameters for this method
*

View File

@ -439,6 +439,23 @@ class DocBlock implements \Reflector
return $tag;
}
/**
* Deletes a tag from the list of tags.
*
* @param Tag $tag The tag to be deleted.
*
* @return bool True if the tag was deleted.
*/
public function deleteTag(Tag $tag)
{
if (($key = array_search($tag, $this->tags)) !== false) {
unset($this->tags[$key]);
return true;
}
return false;
}
/**
* Builds a string representation of this object.

File diff suppressed because it is too large Load Diff

View File

@ -160,7 +160,7 @@ class DatabaseServiceProvider extends ServiceProvider
*/
public function macroUpdateBatch()
{
return function (array $values) {
return function (array $values, $filed = 'id') {
if (empty($values)) {
return false;
}
@ -169,8 +169,6 @@ class DatabaseServiceProvider extends ServiceProvider
$values = [$values];
} else {
foreach ($values as $key => $value) {
ksort($value);
$values[$key] = $value;
}
}
@ -178,7 +176,7 @@ class DatabaseServiceProvider extends ServiceProvider
$grammar = new MySqlGrammar();
return $this->connection->affectingStatement(
$grammar->compileUpdateBatch($this, $values),
$grammar->compileUpdateBatch($this, $values, $filed),
$this->cleanBindings(Arr::flatten($values, 1))
);
};

View File

@ -158,9 +158,10 @@ class MySqlGrammar extends Grammar
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @param string $filed
* @return string
*/
public function compileUpdateBatch(QueryBuilder $query, array $values)
public function compileUpdateBatch(QueryBuilder $query, array $values, $filed = 'id')
{
// Essentially we will force every insert to be treated as a batch insert which
// simply makes creating the SQL easier for us since we can utilize the same
@ -175,9 +176,19 @@ class MySqlGrammar extends Grammar
$columns = array_keys(reset($values));
// 以第一个字段为更新条件
$reference = isset($row['id']) ? 'id' : current($columns);
unset($columns[0]);
// 指定更新字段默认id字段,不存在时选用第一个字段。
if (isset($row[$filed])) {
$reference = $filed;
$key = array_search($filed, $columns);
} else {
$reference = current($columns);
$key = 0;
}
unset($columns[$key]);
$reference = isset($row[$filed]) ? $filed : current($columns);
$sql = "update $table set";

View File

@ -432,30 +432,3 @@ if (!function_exists('db_alter')) {
}
}
}
/*
|--------------------------------------------------------------------------
| 数组处理
|--------------------------------------------------------------------------
|
*/
// 修改数组集合键名
if (!function_exists('array_keyBy')) {
function array_keyBy($arr, $key)
{
return array_combine(array_pluck($arr, $key), $arr);
}
}
// 数组集合分组
if (!function_exists('array_groupBy')) {
function array_groupBy($arr, $key)
{
$temp = [];
foreach ($arr as $item) {
$temp[$item[$key]][] = $item;
}
return $temp;
}
}

View File

@ -195,7 +195,7 @@ class Carbon extends DateTime implements JsonSerializable
't' => '(2[89]|3[01])',
'L' => '(0|1)',
'o' => '([1-9][0-9]{0,4})',
'Y' => '([1-9][0-9]{0,4})',
'Y' => '([1-9]?[0-9]{4})',
'y' => '([0-9]{2})',
'a' => '(am|pm)',
'A' => '(AM|PM)',
@ -217,8 +217,8 @@ class Carbon extends DateTime implements JsonSerializable
'U' => '([0-9]*)',
// The formats below are combinations of the above formats.
'c' => '(([1-9][0-9]{0,4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP
'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9][0-9]{0,4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))', // D, j M Y H:i:s O
'c' => '(([1-9]?[0-9]{4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP
'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9]?[0-9]{4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))', // D, j M Y H:i:s O
);
/**

View File

@ -498,6 +498,11 @@ class CarbonInterval extends DateInterval
{
$instance = new static(static::getDateIntervalSpec($di));
$instance->invert = $di->invert;
foreach (array('y', 'm', 'd', 'h', 'i', 's') as $unit) {
if ($di->$unit < 0) {
$instance->$unit *= -1;
}
}
return $instance;
}
@ -961,15 +966,15 @@ class CarbonInterval extends DateInterval
public static function getDateIntervalSpec(DateInterval $interval)
{
$date = array_filter(array(
static::PERIOD_YEARS => $interval->y,
static::PERIOD_MONTHS => $interval->m,
static::PERIOD_DAYS => $interval->d,
static::PERIOD_YEARS => abs($interval->y),
static::PERIOD_MONTHS => abs($interval->m),
static::PERIOD_DAYS => abs($interval->d),
));
$time = array_filter(array(
static::PERIOD_HOURS => $interval->h,
static::PERIOD_MINUTES => $interval->i,
static::PERIOD_SECONDS => $interval->s,
static::PERIOD_HOURS => abs($interval->h),
static::PERIOD_MINUTES => abs($interval->i),
static::PERIOD_SECONDS => abs($interval->s),
));
$specString = static::PERIOD_PREFIX;