同步增值包

This commit is contained in:
邓皓元 2018-12-10 14:27:38 +08:00
parent b551c5bad8
commit dc5d701299
8 changed files with 234 additions and 10 deletions

View File

@ -20,6 +20,8 @@ class AddedOrderSync extends Command
protected $chunks = 1000; protected $chunks = 1000;
protected $types;
public function handle() public function handle()
{ {
$this->datetime = $this->getDateTime(); $this->datetime = $this->getDateTime();
@ -29,6 +31,10 @@ class AddedOrderSync extends Command
$orders = $this->getOrders(); $orders = $this->getOrders();
$orderItems = $this->getOrderItems($orders); $orderItems = $this->getOrderItems($orders);
foreach ($orders as &$item) {
$item['type'] = $this->types[$item['sn']] ?? 255;
}
$dataOrderCards = []; $dataOrderCards = [];
$dataPackageCards = []; $dataPackageCards = [];
@ -36,8 +42,8 @@ class AddedOrderSync extends Command
$dataOrderCards[$value['type']][] = [ $dataOrderCards[$value['type']][] = [
'sim' => $value['sim'], 'sim' => $value['sim'],
'order_id' => $value['order_id'], 'order_id' => $value['order_id'],
'counts' => $value['item_counts'], 'counts' => $value['counts'],
'unit_price' => $value['item_unit_price'], 'unit_price' => $value['unit_price'],
]; ];
$dataPackageCards[$value['type']][] = [ $dataPackageCards[$value['type']][] = [
@ -53,7 +59,6 @@ class AddedOrderSync extends Command
} }
app(AddedOrderRepository::class)->forgetCached(); app(AddedOrderRepository::class)->forgetCached();
$this->line('插入订单关联数据,条数:'.count(array_collapse($dataOrderCards))); $this->line('插入订单关联数据,条数:'.count(array_collapse($dataOrderCards)));
$tables = [ $tables = [
'', '',
@ -112,6 +117,7 @@ class AddedOrderSync extends Command
]; ];
$orders = DB::connection('real')->table('jxc_custom_order')->select($select)->where('status', 3) $orders = DB::connection('real')->table('jxc_custom_order')->select($select)->where('status', 3)
->whereIn('custom_no', $this->companies->keys())
->where('create_time', '>=', $starttime->timestamp) ->where('create_time', '>=', $starttime->timestamp)
->where('create_time', '<=', $endtime->timestamp) ->where('create_time', '<=', $endtime->timestamp)
->orderBy('create_time')->get()->toArray(); ->orderBy('create_time')->get()->toArray();
@ -122,7 +128,7 @@ class AddedOrderSync extends Command
foreach ($orders as &$item) { foreach ($orders as &$item) {
$item = (array)$item; $item = (array)$item;
$item['company_id'] = $this->companies[$item['company_id']]['id'] ?? 0; $item['company_id'] = $this->companies[$item['company_id']]['id'] ?? 0;
$item['total_price'] = intval($item['total_price'] * 100); $item['total_price'] = floatval($item['total_price']) * 100;
$item['counts'] = !empty($item['counts']) ? $item['counts'] : 1; $item['counts'] = !empty($item['counts']) ? $item['counts'] : 1;
$item['pay_channel'] = 0; $item['pay_channel'] = 0;
@ -132,7 +138,7 @@ class AddedOrderSync extends Command
} }
} }
$item['unit_price'] = intval($total_price/$item['counts']); $item['unit_price'] = intval($item['total_price']/$item['counts']);
$item['order_at'] = date('Y-m-d H:i:s', $item['order_at']); $item['order_at'] = date('Y-m-d H:i:s', $item['order_at']);
$item['created_at'] = $item['order_at']; $item['created_at'] = $item['order_at'];
$item['updated_at'] = ($item['updated_at'] == '0000-00-00 00:00:00') ? $item['order_at'] : $item['updated_at']; $item['updated_at'] = ($item['updated_at'] == '0000-00-00 00:00:00') ? $item['order_at'] : $item['updated_at'];
@ -153,8 +159,8 @@ class AddedOrderSync extends Command
'sim', 'sim',
'goods_no as package_id', 'goods_no as package_id',
'goods_type as type', 'goods_type as type',
'unit_price as item_unit_price', 'unit_price as unit_price',
'quantity as item_counts', 'quantity as counts',
]; ];
$orderItems = DB::connection('real')->table('jxc_custom_order_item')->select($select) $orderItems = DB::connection('real')->table('jxc_custom_order_item')->select($select)
@ -164,9 +170,11 @@ class AddedOrderSync extends Command
$item = (array)$item; $item = (array)$item;
$item['order_id'] = $orders[$item['order_sn']]['id'] ?? 0; $item['order_id'] = $orders[$item['order_sn']]['id'] ?? 0;
$item['package_id'] = $this->packages[$item['package_id']]['id'] ?? 0; $item['package_id'] = $this->packages[$item['package_id']]['id'] ?? 0;
$item['unit_price'] = intval($item['item_unit_price'] * 100); $item['unit_price'] = floatval($item['unit_price']) * 100;
} }
$this->types = array_pluck($orderItems, 'type', 'order_sn');
return $orderItems; return $orderItems;
} }
} }

View File

@ -0,0 +1,62 @@
<?php
namespace App\Domains\Virtual\Repositories;
use App\Core\Repository;
use App\Models\Virtual\CompanyAccount as Model;
class CompanyAccountRepository 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;
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Domains\Virtual\Repositories;
use App\Core\Repository;
use App\Models\Virtual\CompanyAddress as Model;
class CompanyAddressRepository 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;
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Domains\Virtual\Repositories;
use App\Core\Repository;
use App\Models\Virtual\Product as Model;
class ProductRepository 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;
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Models\Virtual;
use App\Core\Model;
class CompanyAccount extends Model
{
protected $table = 'virtual_company_accounts';
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Models\Virtual;
use App\Core\Model;
class CompanyAddress extends Model
{
protected $table = 'virtual_company_addresses';
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Models\Virtual;
use App\Core\Model;
class Product extends Model
{
protected $table = 'virtual_products';
}

View File

@ -173,7 +173,7 @@ class CreateBaseTables extends Migration
$table->unique('phone'); $table->unique('phone');
}); });
Schema::create("virtual_company_address", function (Blueprint $table) { Schema::create("virtual_company_addresses", function (Blueprint $table) {
$table->increments('id')->comment('自增ID'); $table->increments('id')->comment('自增ID');
$table->string('company_id', 32)->comment('企业ID'); $table->string('company_id', 32)->comment('企业ID');
$table->string('contacts', 20)->default('')->comment('联系人'); $table->string('contacts', 20)->default('')->comment('联系人');
@ -219,7 +219,7 @@ class CreateBaseTables extends Migration
Schema::dropIfExists("cards"); Schema::dropIfExists("cards");
Schema::dropIfExists("blocs"); Schema::dropIfExists("blocs");
Schema::dropIfExists("virtual_products"); Schema::dropIfExists("virtual_products");
Schema::dropIfExists("virtual_company_address"); Schema::dropIfExists("virtual_company_addresses");
Schema::dropIfExists("virtual_company_accounts"); Schema::dropIfExists("virtual_company_accounts");
} }
} }