diff --git a/app/Domains/Real/Commands/Sync/AddedOrderSync.php b/app/Domains/Real/Commands/Sync/AddedOrderSync.php index 27333630..1f751de8 100644 --- a/app/Domains/Real/Commands/Sync/AddedOrderSync.php +++ b/app/Domains/Real/Commands/Sync/AddedOrderSync.php @@ -20,6 +20,8 @@ class AddedOrderSync extends Command protected $chunks = 1000; + protected $types; + public function handle() { $this->datetime = $this->getDateTime(); @@ -29,6 +31,10 @@ class AddedOrderSync extends Command $orders = $this->getOrders(); $orderItems = $this->getOrderItems($orders); + foreach ($orders as &$item) { + $item['type'] = $this->types[$item['sn']] ?? 255; + } + $dataOrderCards = []; $dataPackageCards = []; @@ -36,8 +42,8 @@ class AddedOrderSync extends Command $dataOrderCards[$value['type']][] = [ 'sim' => $value['sim'], 'order_id' => $value['order_id'], - 'counts' => $value['item_counts'], - 'unit_price' => $value['item_unit_price'], + 'counts' => $value['counts'], + 'unit_price' => $value['unit_price'], ]; $dataPackageCards[$value['type']][] = [ @@ -53,7 +59,6 @@ class AddedOrderSync extends Command } app(AddedOrderRepository::class)->forgetCached(); - $this->line('插入订单关联数据,条数:'.count(array_collapse($dataOrderCards))); $tables = [ '', @@ -112,6 +117,7 @@ class AddedOrderSync extends Command ]; $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', '<=', $endtime->timestamp) ->orderBy('create_time')->get()->toArray(); @@ -122,7 +128,7 @@ class AddedOrderSync extends Command foreach ($orders as &$item) { $item = (array)$item; $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['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['created_at'] = $item['order_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', 'goods_no as package_id', 'goods_type as type', - 'unit_price as item_unit_price', - 'quantity as item_counts', + 'unit_price as unit_price', + 'quantity as counts', ]; $orderItems = DB::connection('real')->table('jxc_custom_order_item')->select($select) @@ -164,9 +170,11 @@ class AddedOrderSync extends Command $item = (array)$item; $item['order_id'] = $orders[$item['order_sn']]['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; } } diff --git a/app/Domains/Virtual/Repositories/CompanyAccountRepository.php b/app/Domains/Virtual/Repositories/CompanyAccountRepository.php new file mode 100644 index 00000000..0860a161 --- /dev/null +++ b/app/Domains/Virtual/Repositories/CompanyAccountRepository.php @@ -0,0 +1,62 @@ + '=', + '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; + } +} \ No newline at end of file diff --git a/app/Domains/Virtual/Repositories/CompanyAddressRepository.php b/app/Domains/Virtual/Repositories/CompanyAddressRepository.php new file mode 100644 index 00000000..0ae84dd7 --- /dev/null +++ b/app/Domains/Virtual/Repositories/CompanyAddressRepository.php @@ -0,0 +1,62 @@ + '=', + '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; + } +} \ No newline at end of file diff --git a/app/Domains/Virtual/Repositories/ProductRepository.php b/app/Domains/Virtual/Repositories/ProductRepository.php new file mode 100644 index 00000000..3e557b8b --- /dev/null +++ b/app/Domains/Virtual/Repositories/ProductRepository.php @@ -0,0 +1,62 @@ + '=', + '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; + } +} \ No newline at end of file diff --git a/app/Models/Virtual/CompanyAccount.php b/app/Models/Virtual/CompanyAccount.php new file mode 100644 index 00000000..dcbde475 --- /dev/null +++ b/app/Models/Virtual/CompanyAccount.php @@ -0,0 +1,10 @@ +unique('phone'); }); - Schema::create("virtual_company_address", function (Blueprint $table) { + Schema::create("virtual_company_addresses", function (Blueprint $table) { $table->increments('id')->comment('自增ID'); $table->string('company_id', 32)->comment('企业ID'); $table->string('contacts', 20)->default('')->comment('联系人'); @@ -219,7 +219,7 @@ class CreateBaseTables extends Migration Schema::dropIfExists("cards"); Schema::dropIfExists("blocs"); Schema::dropIfExists("virtual_products"); - Schema::dropIfExists("virtual_company_address"); + Schema::dropIfExists("virtual_company_addresses"); Schema::dropIfExists("virtual_company_accounts"); } }