84 lines
1.7 KiB
PHP
84 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Real\Repositories;
|
|
|
|
use App\Core\Repository;
|
|
use App\Models\Real\OrderCard as Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OrderCardRepository extends Repository
|
|
{
|
|
/**
|
|
* 是否关闭缓存
|
|
*
|
|
* @var boolean
|
|
*/
|
|
protected $cacheSkip = false;
|
|
|
|
/**
|
|
* 是否开启数据转化
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $needTransform = false;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fieldSearchable = [
|
|
'id' => '=',
|
|
'created_at' => 'like',
|
|
];
|
|
|
|
public function model()
|
|
{
|
|
return Model::class;
|
|
}
|
|
|
|
/**
|
|
* 数据格式化
|
|
*
|
|
* @param mixed $result
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function transform($model)
|
|
{
|
|
return $model->toArray();
|
|
}
|
|
|
|
/**
|
|
* 查询条件
|
|
*
|
|
* @return void
|
|
*/
|
|
public function withConditions(array $conditions = [])
|
|
{
|
|
if (isset($conditions['id'])) {
|
|
$conditions['id'] = array_wrap($conditions['id']);
|
|
$this->model = $this->model->whereIn('id', $conditions['id']);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
|
|
/**
|
|
* 批量更新激活时间
|
|
*
|
|
* @return void
|
|
*/
|
|
public function updateActivateAt(array $data)
|
|
{
|
|
$connection = $this->model->getConnection();
|
|
|
|
$arr = array_map(function ($value) {
|
|
return sprintf("(%d, '%s'::timestamp)", $value['sim'], $value['activated_at']);
|
|
}, $data);
|
|
|
|
$sql = 'UPDATE real_cards SET activated_at = list.activated_at FROM (VALUES ' . implode(',', $arr) . ') AS list(sim, activated_at) WHERE real_cards.sim = list.sim AND real_cards.activated_at IS NULL';
|
|
|
|
return $connection->update($sql);
|
|
}
|
|
}
|