From 7dade947a44e6ae7edf0b56ba6331c52e38d6468 Mon Sep 17 00:00:00 2001 From: denghy Date: Mon, 24 Dec 2018 17:43:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...018_08_08_170019_create_accounts_table.php | 4 + ...2018_08_09_154046_create_configs_table.php | 4 + .../2018_08_10_092334_create_file_tables.php | 66 ++-- .../2018_08_14_142405_create_logs.php | 4 + ..._08_08_170540_create_permission_tables.php | 92 +++--- .../Real/Commands/Sync/AddedOrderSync.php | 33 +- app/Domains/Real/Commands/Sync/BlocSync.php | 7 +- app/Domains/Real/Commands/Sync/MongoSync.php | 2 +- .../Virtual/Commands/Sync/CardSync.php | 286 ++++++++++++++++++ .../Virtual/Commands/Sync/ProductSync.php | 6 +- .../Providers/VirtualServiceProvider.php | 1 + ...epository.php => AddedOrderRepository.php} | 32 +- .../Virtual/Services/AddedOrderService.php | 208 +++++++++++++ app/Models/Real/OrderCard.php | 10 +- app/Models/Virtual/OrderCard.php | 10 +- composer.lock | 12 +- ..._11_16_190020_create_failed_jobs_table.php | 4 + .../2018_11_27_175137_create_base_tables.php | 234 -------------- .../2018_11_27_175146_create_order_tables.php | 61 ---- ...018_11_27_175152_create_package_tables.php | 46 --- .../2018_12_24_164210_create_blocs_table.php | 46 +++ .../2018_12_24_164218_create_cards_table.php | 45 +++ ..._24_164318_create_real_companies_table.php | 46 +++ ...2_24_164423_create_real_packages_table.php | 63 ++++ ..._12_24_164430_create_real_orders_table.php | 57 ++++ ...4_164434_create_real_order_cards_table.php | 45 +++ ..._164457_create_real_added_orders_table.php | 53 ++++ ...9_create_real_added_order_cards_tables.php | 53 ++++ ..._164716_create_virtual_companies_table.php | 46 +++ ...4_164722_create_virtual_packages_table.php | 63 ++++ ..._create_virtual_company_accounts_table.php | 46 +++ ...create_virtual_company_addresses_table.php | 45 +++ ...4_164742_create_virtual_products_table.php | 47 +++ ...24_164779_create_virtual_orders_table.php} | 18 +- ...65555_create_virtual_order_cards_table.php | 45 +++ ...0936_create_virtual_added_orders_table.php | 54 ++++ ...reate_virtual_added_order_cards_tables.php | 53 ++++ vendor/composer/autoload_classmap.php | 23 +- vendor/composer/autoload_static.php | 23 +- vendor/composer/installed.json | 14 +- .../src/Database/DatabaseServiceProvider.php | 4 +- .../foundation/src/Database/MySqlGrammar.php | 6 +- .../src/Database/PostgresGrammar.php | 6 +- .../dipper/foundation/src/ServiceProvider.php | 6 + 44 files changed, 1528 insertions(+), 501 deletions(-) create mode 100644 app/Domains/Virtual/Commands/Sync/CardSync.php rename app/Domains/Virtual/Repositories/{BlocRepository.php => AddedOrderRepository.php} (54%) create mode 100644 app/Domains/Virtual/Services/AddedOrderService.php delete mode 100644 database/migrations/2018_11_27_175137_create_base_tables.php delete mode 100644 database/migrations/2018_11_27_175146_create_order_tables.php delete mode 100644 database/migrations/2018_11_27_175152_create_package_tables.php create mode 100644 database/migrations/2018_12_24_164210_create_blocs_table.php create mode 100644 database/migrations/2018_12_24_164218_create_cards_table.php create mode 100644 database/migrations/2018_12_24_164318_create_real_companies_table.php create mode 100644 database/migrations/2018_12_24_164423_create_real_packages_table.php create mode 100644 database/migrations/2018_12_24_164430_create_real_orders_table.php create mode 100644 database/migrations/2018_12_24_164434_create_real_order_cards_table.php create mode 100644 database/migrations/2018_12_24_164457_create_real_added_orders_table.php create mode 100644 database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php create mode 100644 database/migrations/2018_12_24_164716_create_virtual_companies_table.php create mode 100644 database/migrations/2018_12_24_164722_create_virtual_packages_table.php create mode 100644 database/migrations/2018_12_24_164728_create_virtual_company_accounts_table.php create mode 100644 database/migrations/2018_12_24_164735_create_virtual_company_addresses_table.php create mode 100644 database/migrations/2018_12_24_164742_create_virtual_products_table.php rename database/migrations/{2018_12_12_170419_create_virtual_orders_table.php => 2018_12_24_164779_create_virtual_orders_table.php} (87%) create mode 100644 database/migrations/2018_12_24_165555_create_virtual_order_cards_table.php create mode 100644 database/migrations/2018_12_24_170936_create_virtual_added_orders_table.php create mode 100644 database/migrations/2018_12_24_170946_create_virtual_added_order_cards_tables.php diff --git a/app/Domains/Account/Database/migrations/2018_08_08_170019_create_accounts_table.php b/app/Domains/Account/Database/migrations/2018_08_08_170019_create_accounts_table.php index a94d502d..efcff1d6 100644 --- a/app/Domains/Account/Database/migrations/2018_08_08_170019_create_accounts_table.php +++ b/app/Domains/Account/Database/migrations/2018_08_08_170019_create_accounts_table.php @@ -13,6 +13,10 @@ class CreateAccountsTable extends Migration */ public function up() { + if (Schema::hasTable('accounts')) { + return; + } + Schema::create('accounts', function (Blueprint $table) { $table->increments('id')->comment('账户ID'); $table->string('username', 32)->default('')->comment('登录名'); diff --git a/app/Domains/Config/Database/migrations/2018_08_09_154046_create_configs_table.php b/app/Domains/Config/Database/migrations/2018_08_09_154046_create_configs_table.php index c4cd7f26..21de840f 100644 --- a/app/Domains/Config/Database/migrations/2018_08_09_154046_create_configs_table.php +++ b/app/Domains/Config/Database/migrations/2018_08_09_154046_create_configs_table.php @@ -13,6 +13,10 @@ class CreateConfigsTable extends Migration */ public function up() { + if (Schema::hasTable('configs')) { + return; + } + Schema::create('configs', function (Blueprint $table) { $table->string('name', 100)->comment('配置名称'); $table->text('value')->nullable()->comment('缓存值'); diff --git a/app/Domains/File/Database/migrations/2018_08_10_092334_create_file_tables.php b/app/Domains/File/Database/migrations/2018_08_10_092334_create_file_tables.php index cdba960d..affc6364 100644 --- a/app/Domains/File/Database/migrations/2018_08_10_092334_create_file_tables.php +++ b/app/Domains/File/Database/migrations/2018_08_10_092334_create_file_tables.php @@ -13,42 +13,46 @@ class CreateFileTables extends Migration */ public function up() { - // 文件表 - Schema::create('files', function (Blueprint $table) { - $table->bigInteger('id')->unsigned()->default(0)->comment('附件全局唯一ID'); - $table->string('hash', 150)->comment('文件 hash'); - $table->string('disk', 16)->default('')->comment('盘符'); - $table->string('filename')->default('')->comment('文件名'); - $table->string('origin_filename')->nullbale()->default(null)->comment('原始文件名'); - $table->string('mimetype', 32)->default('')->comment('mime type'); - $table->integer('filesize')->unsigned()->default(0)->comment('文件大小'); - $table->integer('width')->unsigned()->default(0)->comment('宽度'); - $table->integer('height')->unsigned()->default(0)->comment('高度'); - $table->decimal('duration', 10, 6)->default(0.000000)->comment('持续时间'); - $table->tinyInteger('thumb')->unsigned()->default(0)->comment('是否有缩略图 0:无 1:有'); - $table->timestamps(); + if (!Schema::hasTable('files')) { + // 文件表 + Schema::create('files', function (Blueprint $table) { + $table->bigInteger('id')->unsigned()->default(0)->comment('附件全局唯一ID'); + $table->string('hash', 150)->comment('文件 hash'); + $table->string('disk', 16)->default('')->comment('盘符'); + $table->string('filename')->default('')->comment('文件名'); + $table->string('origin_filename')->nullbale()->default(null)->comment('原始文件名'); + $table->string('mimetype', 32)->default('')->comment('mime type'); + $table->integer('filesize')->unsigned()->default(0)->comment('文件大小'); + $table->integer('width')->unsigned()->default(0)->comment('宽度'); + $table->integer('height')->unsigned()->default(0)->comment('高度'); + $table->decimal('duration', 10, 6)->default(0.000000)->comment('持续时间'); + $table->tinyInteger('thumb')->unsigned()->default(0)->comment('是否有缩略图 0:无 1:有'); + $table->timestamps(); - $table->primary('id'); + $table->primary('id'); - $table->comment('文件表'); - }); + $table->comment('文件表'); + }); + } - // 文件关联表 - Schema::create('file_withs', function (Blueprint $table) { - $table->increments('id'); - $table->bigInteger('file_id')->unsigned()->default(0)->comment('文件ID'); - $table->integer('account_id')->unsigned()->default(0)->comment('账号ID'); - $table->string('type_id', 100)->default('')->comment('类型ID'); - $table->string('type', 100)->default('')->comment('记录类型'); - $table->timestamps(); - $table->softDeletes(); + if (!Schema::hasTable('file_withs')) { + // 文件关联表 + Schema::create('file_withs', function (Blueprint $table) { + $table->increments('id'); + $table->bigInteger('file_id')->unsigned()->default(0)->comment('文件ID'); + $table->integer('account_id')->unsigned()->default(0)->comment('账号ID'); + $table->string('type_id', 100)->default('')->comment('类型ID'); + $table->string('type', 100)->default('')->comment('记录类型'); + $table->timestamps(); + $table->softDeletes(); - $table->index('file_id'); - $table->index('account_id'); - $table->index(['type', 'type_id']); + $table->index('file_id'); + $table->index('account_id'); + $table->index(['type', 'type_id']); - $table->comment('文件关联表'); - }); + $table->comment('文件关联表'); + }); + } } /** diff --git a/app/Domains/Log/Database/migrations/2018_08_14_142405_create_logs.php b/app/Domains/Log/Database/migrations/2018_08_14_142405_create_logs.php index 8f649808..8dd5f99c 100644 --- a/app/Domains/Log/Database/migrations/2018_08_14_142405_create_logs.php +++ b/app/Domains/Log/Database/migrations/2018_08_14_142405_create_logs.php @@ -13,6 +13,10 @@ class CreateLogs extends Migration */ public function up() { + if (Schema::hasTable('logs')) { + return; + } + Schema::create('logs', function (Blueprint $table) { $table->bigInteger('id')->unsigned()->default(0)->comment('日志ID'); $table->string('request_url', 255)->default('')->comment('请求地址'); diff --git a/app/Domains/Permission/Database/migrations/2018_08_08_170540_create_permission_tables.php b/app/Domains/Permission/Database/migrations/2018_08_08_170540_create_permission_tables.php index 62b10d10..0fd0b634 100644 --- a/app/Domains/Permission/Database/migrations/2018_08_08_170540_create_permission_tables.php +++ b/app/Domains/Permission/Database/migrations/2018_08_08_170540_create_permission_tables.php @@ -13,51 +13,59 @@ class CreatePermissionTables extends Migration */ public function up() { - Schema::create('permissions', function (Blueprint $table) { - $table->increments('id'); - $table->string('name', 32)->default('')->comment('标识'); - $table->string('title', 32)->default('')->comment('名称'); - $table->string('description')->default('')->comment('描述'); - $table->string('path')->default('')->comment('路径'); - $table->string('icon')->default('')->comment('图标'); - $table->tinyInteger('type')->unsigned()->default(0)->comment('类型 0:页面 1:接口'); - $table->tinyInteger('status')->unsigned()->default(1)->comment('状态 0:关闭 1:启用'); - $table->tinyInteger('open')->unsigned()->default(0)->comment('打开方式: 0:iframe方式 1打开新窗口 2:弹出窗口 3:vue组件'); - $table->mediumInteger('height')->unsigned()->default(0)->comment('页面高度'); - $table->mediumInteger('width')->unsigned()->default(0)->comment('页面宽度'); - $table->tinyInteger('displayorder')->unsigned()->default(0)->comment('排序'); - $table->nestedset(); - $table->timestamps(); + if (!Schema::hasTable('permissions')) { + Schema::create('permissions', function (Blueprint $table) { + $table->increments('id'); + $table->string('name', 32)->default('')->comment('标识'); + $table->string('title', 32)->default('')->comment('名称'); + $table->string('description')->default('')->comment('描述'); + $table->string('path')->default('')->comment('路径'); + $table->string('icon')->default('')->comment('图标'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('类型 0:页面 1:接口'); + $table->tinyInteger('status')->unsigned()->default(1)->comment('状态 0:关闭 1:启用'); + $table->tinyInteger('open')->unsigned()->default(0)->comment('打开方式: 0:iframe方式 1打开新窗口 2:弹出窗口 3:vue组件'); + $table->mediumInteger('height')->unsigned()->default(0)->comment('页面高度'); + $table->mediumInteger('width')->unsigned()->default(0)->comment('页面宽度'); + $table->tinyInteger('displayorder')->unsigned()->default(0)->comment('排序'); + $table->nestedset(); + $table->timestamps(); + + $table->comment('权限表'); + }); + } - $table->comment('权限表'); - }); + if (!Schema::hasTable('roles')) { + Schema::create('roles', function (Blueprint $table) { + $table->increments('id'); + $table->string('name', 32)->default('')->comment('标识'); + $table->string('remark')->default('')->comment('备注'); + $table->nestedset(); + $table->timestamps(); + $table->unique(['name']); + + $table->comment('角色表'); + }); + } - Schema::create('roles', function (Blueprint $table) { - $table->increments('id'); - $table->string('name', 32)->default('')->comment('标识'); - $table->string('remark')->default('')->comment('备注'); - $table->nestedset(); - $table->timestamps(); - $table->unique(['name']); + if (!Schema::hasTable('account_has_roles')) { + Schema::create('account_has_roles', function (Blueprint $table) use ($tableNames) { + $table->unsignedInteger('role_id'); + $table->unsignedInteger('account_id'); + $table->primary(['role_id', 'account_id']); + + $table->comment('账号角色关联表'); + }); + } - $table->comment('角色表'); - }); - - Schema::create('account_has_roles', function (Blueprint $table) use ($tableNames) { - $table->unsignedInteger('role_id'); - $table->unsignedInteger('account_id'); - $table->primary(['role_id', 'account_id']); - - $table->comment('账号角色关联表'); - }); - - Schema::create('role_has_permissions', function (Blueprint $table) use ($tableNames) { - $table->unsignedInteger('permission_id'); - $table->unsignedInteger('role_id'); - $table->primary(['permission_id', 'role_id']); - - $table->comment('角色权限关联表'); - }); + if (!Schema::hasTable('role_has_permissions')) { + Schema::create('role_has_permissions', function (Blueprint $table) use ($tableNames) { + $table->unsignedInteger('permission_id'); + $table->unsignedInteger('role_id'); + $table->primary(['permission_id', 'role_id']); + + $table->comment('角色权限关联表'); + }); + } } /** diff --git a/app/Domains/Real/Commands/Sync/AddedOrderSync.php b/app/Domains/Real/Commands/Sync/AddedOrderSync.php index 0ca11990..0b90beb7 100644 --- a/app/Domains/Real/Commands/Sync/AddedOrderSync.php +++ b/app/Domains/Real/Commands/Sync/AddedOrderSync.php @@ -36,20 +36,16 @@ class AddedOrderSync extends Command } $dataOrderCards = []; - $dataPackageCards = []; foreach ($orderItems as $key => $value) { $dataOrderCards[$value['type']][] = [ 'sim' => $value['sim'], + 'company_id' => $value['company_id'], 'order_id' => $value['order_id'], + 'package_id' => $value['package_id'], 'counts' => $value['counts'], 'unit_price' => $value['unit_price'], ]; - - $dataPackageCards[$value['type']][] = [ - 'package_id' => $value['package_id'], - 'sim' => $value['sim'], - ]; } $this->line('插入订单数据,条数:'.count($orders)); @@ -76,24 +72,6 @@ class AddedOrderSync extends Command } unset($dataOrderCards); $this->line('插入订单关联数据成功'); - - $this->line('插入套餐关联数据,条数:'.count(array_collapse($dataPackageCards))); - $tables = [ - '', - 'real_package_renewal_cards', - 'real_package_renewal_package_cards', - 'real_package_flows_package_cards', - 'real_package_optional_package_cards', - 'real_package_additional_package_cards', - ]; - foreach ($dataPackageCards as $type => $packageCards) { - foreach (array_chunk($packageCards, $this->chunks) as $data) { - echo '.'; - DB::table($tables[$type])->upsert($data, ['sim', 'package_id']); - } - } - unset($dataPackageCards); - $this->line('插入套餐关联数据成功'); } // 查询订单 @@ -120,10 +98,9 @@ class AddedOrderSync extends Command ->whereIn('custom_no', $this->companies->keys()) ->where('create_time', '>=', $starttime->timestamp) ->where('create_time', '<=', $endtime->timestamp) - ->orderBy('create_time')->get()->toArray(); + ->orderBy('create_time')->get()->collect()->toArray(); foreach ($orders as &$item) { - $item = (array)$item; $item['company_id'] = $this->companies[$item['company_id']]['id'] ?? 0; $item['total_price'] = floatval($item['total_price']) * 100; $item['counts'] = !empty($item['counts']) ? $item['counts'] : 1; @@ -154,11 +131,11 @@ class AddedOrderSync extends Command ]; $orderItems = DB::connection('real')->table('jxc_custom_order_item')->select($select) - ->whereIn('sn', array_keys($orders))->where('goods_type', '<', 6)->get()->toArray(); + ->whereIn('sn', array_keys($orders))->where('goods_type', '<', 6)->get()->collect()->toArray(); foreach ($orderItems as &$item) { - $item = (array)$item; $item['order_id'] = $orders[$item['order_sn']]['id'] ?? 0; + $item['company_id'] = $orders[$item['order_sn']]['company_id'] ?? 0; $item['package_id'] = $this->packages[$item['package_id']]['id'] ?? 0; $item['unit_price'] = floatval($item['unit_price']) * 100; } diff --git a/app/Domains/Real/Commands/Sync/BlocSync.php b/app/Domains/Real/Commands/Sync/BlocSync.php index 4fb356cc..960cfb38 100644 --- a/app/Domains/Real/Commands/Sync/BlocSync.php +++ b/app/Domains/Real/Commands/Sync/BlocSync.php @@ -20,13 +20,12 @@ class BlocSync extends Command { $select = ['id', 'bloc_code as sn', "bloc_name as name", 'carrieroperator as carrier_operator', 'create_time as created_at', 'del']; - $blocs = DB::connection('real')->table('jxc_bloc_manage')->select($select)->get()->toArray(); - $carders = DB::connection('real')->table('jxc_carder_manage')->select(['bloc_code', 'inside_card_from_sn'])->get()->toArray(); + $blocs = DB::connection('real')->table('jxc_bloc_manage')->select($select)->get()->collect()->toArray(); + $carders = DB::connection('real')->table('jxc_carder_manage')->select(['bloc_code', 'inside_card_from_sn'])->get()->collect()->toArray(); $carders = array_pluck($carders, 'inside_card_from_sn', 'bloc_code'); foreach ($blocs as &$item) { - $item = (array)$item; - $item['shorthand'] = $carders[$item['id']] ?? ''; + $item['shorthand'] = $carders[$item['sn']] ?? ''; $item['carrier_operator'] = $this->carrier_operator[$item['carrier_operator']]; $item['created_at'] = Carbon::createFromTimestamp($item['created_at']); $item['updated_at'] = date('Y-m-d H:i:s'); diff --git a/app/Domains/Real/Commands/Sync/MongoSync.php b/app/Domains/Real/Commands/Sync/MongoSync.php index 735ba12a..e8820e38 100644 --- a/app/Domains/Real/Commands/Sync/MongoSync.php +++ b/app/Domains/Real/Commands/Sync/MongoSync.php @@ -68,7 +68,7 @@ class MongoSync extends Command ]; } - Card::upsert($values, 'sim'); + Card::upsert($values, 'sim', true); if ($page * $this->limit >= $total) { break; diff --git a/app/Domains/Virtual/Commands/Sync/CardSync.php b/app/Domains/Virtual/Commands/Sync/CardSync.php new file mode 100644 index 00000000..f760188e --- /dev/null +++ b/app/Domains/Virtual/Commands/Sync/CardSync.php @@ -0,0 +1,286 @@ + 0, 11 => 1, 12 => 2]; + protected static $payChannels = [10 => 'wx', 11 => 'alipay', 12 => 'bank']; + + protected $blocs; + protected $packages; + protected $product; + + protected $limit = 1; + + const FILENAME = 'app/command/sync-card.json'; + const INIT_ID = 0; // '2000-01-01 00:00:00' + + public function handle() + { + $contents = $this->getFile(); + $maxId = $contents['maxId']; + $nextId = $contents['maxId']; + + $this->saveFile(1, $maxId); + + $query = DB::connection('vd_old')->table('ckb_custom') + ->select(['id', 'custom_no', 'imsi', 'carrieroperator', 'iccid', 'card_number', 'card_from', 'iccid', 'company', 'custom_state']) + ->where('id', '>', $maxId); + + $logQuery = DB::connection('vd_old')->table('ckb_custom_handle_log') + ->select(['type', 'company', 'pay_type', 'content', 'valid_start_time', 'valid_end_time', 'sale_account', 'order_account', 'create_time']); + + $total = $query->count(); + + $this->line('待同步条数:' . $total); + + if ($total) { + $this->blocs = app(BlocRepository::class)->get()->pluck('id', 'shorthand')->toArray(); + $this->packages = app(PackageRepository::class)->get()->keyBy('sn'); + $this->product = app(ProductRepository::class)->get()->keyBy('sn'); + } + + $page = 1; + + while ($total) { + echo $page . PHP_EOL; + $value = $query->offset(($page - 1) * $this->limit)->limit($this->limit)->get()->first(); + + if (!$value) { + break; + } + + $value = (array)$value; + + $logs = $logQuery->where('custom_no', $value['custom_no'])->get()->collect(); + $existedCard = Card::where('sim', $value['card_number'])->first(); + + dd($logs); + + $card = $this->transformerCard($value, $logs, $existedCard); + $order = $this->transformerOrder($value, $logs, $existedCard); + $renewals = $this->transformerRenewals($value, $logs, $existedCard); + $renewalPackages = $this->transformerRenewalPackages($value, $logs, $existedCard); + $flows = $this->transformerFlows($value, $logs, $existedCard); + + $nextId = $value['id']; + + if ($page * $this->limit >= $total) { + break; + } + + $page++; + } + + app(CardRepository::class)->forgetCached(); + + $this->saveFile(0, $nextId); + } + + // 卡数据转换 + protected function transformerCard($value, $logs, $existedCard) + { + // 判断卡类型 + $type = ($value['card_number'][3] >= 5) ? 1 : ($existedCard ? 0 : 2); + + // 激活记录 + $activateLog = $logs->where('type', 10)->first(); + $activate_at = $activateLog ? date('Y-m-d H:i:s', $activateLog['valid_start_time']) : null; + + return [ + 'sim' => $value['card_number'], + 'imsi' => $value['imsi'], + 'iccid' => $value['iccid'], + 'bloc_id' => $this->blocs[$value['card_from']] ?? 0, + 'carrier_operator' => self::$carrierOperators[$value['carrieroperator']], + 'activate_at' => $existedCard ? $existedCard->activate_at : $activate_at, + 'virtual_activate_at' => $activate_at, + 'type' => $type, + ]; + } + + // 销售记录 + protected function transformerOrder($value, $logs, $existedCard) + { + if (!$sellLog = $logs->where('type', 13)->first()) { + return null; + } + + $package = $this->getPackage($sellLog['content']); + + $unit_price = floatval($sellLog['sale_account']) * 100; + $custom_price = floatval($sellLog['order_account']) * 100; + + $product = $this->getProduct($package, $sellLog['company'], $unit_price); + + $order = [ + 'type' => 1, + 'company_id' => $sellLog['company'], + 'package_id' => $package['id'], + 'product_id' => $product['id'], + 'pay_channel' => self::$payChannels[$sellLog['pay_type']], + 'unit_price' => $unit_price, + 'counts' => DB::raw('counts + 1'), + 'total_price' => DB::raw("total_price + {$unit_price}"), + 'custom_price' => DB::raw("custom_price + {$custom_price}"), + 'order_at' => date('Y-m-d H:i:s'), + 'order_status' => 4, + 'transaction_status' => 1, + ]; + + return $order; + } + + // 续费记录 + protected function transformerRenewals($value, $logs, $existedCard) + { + $renewalLogs = $logs->where('type', 11)->get(); + + if (empty($renewalLog)) { + return []; + } + + $array = []; + + foreach ($renewalLogs as $item) { + $package = $this->getPackage($sellLog['content']); + $unit_price = floatval($sellLog['sale_account']) * 100; + $custom_price = floatval($sellLog['order_account']) * 100; + + $array[] = [ + 'sn' => $sn, + 'type' => 1, + 'company_id' => $sellLog['company'], + 'package_id' => $package['id'], + 'product_id' => $product['id'], + 'pay_channel' => self::$payChannels[$sellLog['pay_type']], + 'unit_price' => $unit_price, + 'counts' => DB::raw('counts + 1'), + 'total_price' => DB::raw("total_price + {$unit_price}"), + 'custom_price' => DB::raw("custom_price + {$custom_price}"), + 'order_at' => date('Y-m-d H:i:s'), + 'order_status' => 4, + 'transaction_status' => 1, + ]; + } + + return $array; + } + + // 续费包记录 + protected function transformerRenewalPackages($value, $logs, $existedCard) + { + $renewalLog = $logs->where('type', 14)->get(); + + if (empty($renewalLog)) { + return []; + } + } + + // 加油包记录 + protected function transformerFlows($value, $logs, $existedCard) + { + $flowsLog = $logs->where('type', 15)->get(); + + if (empty($flowsLog)) { + return []; + } + } + + /** + * 获取套餐 + * + * @param string $sn + * @return void + */ + protected function getPackage($sn) + { + if (!$package = $this->packages[$sn]) { + throw new \Exception('套餐不存在'); + } + + return $package; + } + + /** + * 获取定价 + * + * @param string $sn + * @return void + */ + protected function getProduct($package, $companyId, $price) + { + $sn = strtoupper($package['sn'] . '_' . $companyId . '_' . $price); + + if (!$product = $this->products[$sn]) { + $product = app(ProductService::class)->store([ + 'name' => $package['name'] . '' . $price, + 'company_id' => $companyId, + 'package_id' => $package['id'], + 'base_price' => $price, + 'renewal_price' => $price, + ]); + $this->products[$sn] = $product; + } + + return $product; + } + + /** + * 获取文件内容 + * + * @return void + */ + protected function getFile() + { + $file = storage_path(self::FILENAME); + + if (!file_exists($file)) { + $dir = dirname($file); + if (null !== $dir && !is_dir($dir)) { + mkdir($dir, 0777, true); + } + + $this->saveFile(0, self::INIT_ID); + } + + $contents = file_get_contents($file); + + return json_decode($contents, 256); + } + + /** + * 写入文件 + * + * @param integer $status 状态 1运行中 0运行结束 + * @param integer $maxId 最后查询的ID + * @return void + */ + protected function saveFile(int $status, int $maxId) + { + $file = storage_path(self::FILENAME); + + $contents = json_encode([ + 'status' => $status, + 'maxId' => $maxId, + ]); + + file_put_contents($file, $contents); + } +} diff --git a/app/Domains/Virtual/Commands/Sync/ProductSync.php b/app/Domains/Virtual/Commands/Sync/ProductSync.php index 0d5ef6a3..774738cb 100644 --- a/app/Domains/Virtual/Commands/Sync/ProductSync.php +++ b/app/Domains/Virtual/Commands/Sync/ProductSync.php @@ -19,7 +19,7 @@ class ProductSync extends Command { $packages = app(PackageRepository::class)->where('type', 0)->get()->keyBy('sn')->toArray(); - $fields = ['company', 'content', 'order_account']; + $fields = ['company', 'content', 'sale_account']; $list = DB::connection('vd_old')->table('ckb_custom_handle_log')->select($fields) ->where('type', 13) @@ -33,13 +33,13 @@ class ProductSync extends Command throw new \Exception('套餐不存在'); } - $base_price = floatval($value['order_account']) * 100; + $base_price = floatval($value['sale_account']) * 100; $products[] = [ 'sn' => strtoupper($package['sn'] . '_' . $value['company'] . '_' . $base_price), 'company_id' => $value['company'], 'package_id' => $package['id'], - 'name' => $package['name'] . ' ' . $value['order_account'], + 'name' => $package['name'] . ' ' . $value['sale_account'], 'base_price' => $base_price, 'renewal_price' => 0, 'created_at' => date('Y-m-d H:i:s'), diff --git a/app/Domains/Virtual/Providers/VirtualServiceProvider.php b/app/Domains/Virtual/Providers/VirtualServiceProvider.php index 48194a59..cf5ca19e 100644 --- a/app/Domains/Virtual/Providers/VirtualServiceProvider.php +++ b/app/Domains/Virtual/Providers/VirtualServiceProvider.php @@ -25,6 +25,7 @@ class VirtualServiceProvider extends ServiceProvider \App\Domains\Virtual\Commands\Sync\CompanySync::class, \App\Domains\Virtual\Commands\Sync\PackageSync::class, \App\Domains\Virtual\Commands\Sync\ProductSync::class, + \App\Domains\Virtual\Commands\Sync\CardSync::class, ]); } diff --git a/app/Domains/Virtual/Repositories/BlocRepository.php b/app/Domains/Virtual/Repositories/AddedOrderRepository.php similarity index 54% rename from app/Domains/Virtual/Repositories/BlocRepository.php rename to app/Domains/Virtual/Repositories/AddedOrderRepository.php index 2d9af43c..1559d6da 100644 --- a/app/Domains/Virtual/Repositories/BlocRepository.php +++ b/app/Domains/Virtual/Repositories/AddedOrderRepository.php @@ -3,9 +3,10 @@ namespace App\Domains\Virtual\Repositories; use App\Core\Repository; -use App\Models\Virtual\Bloc as Model; +use App\Models\Virtual\Order as Model; +use App\Domains\Virtual\Services\CommonService; -class BlocRepository extends Repository +class AddedOrderRepository extends Repository { /** * 是否关闭缓存 @@ -16,7 +17,7 @@ class BlocRepository extends Repository /** * 是否开启数据转化 - * + * * @var bool */ protected $needTransform = false; @@ -25,11 +26,13 @@ class BlocRepository extends Repository * @var array */ protected $fieldSearchable = [ - 'id' => '=', - 'created_at' => 'like', + 'id' => '=', + 'sn' => 'like', + 'package.name' => 'like', ]; - public function model() { + public function model() + { return Model::class; } @@ -42,7 +45,7 @@ class BlocRepository extends Repository */ public function transform($model) { - return $model->toArray(); + return $model; } /** @@ -57,6 +60,19 @@ class BlocRepository extends Repository $this->model = $this->model->whereIn('id', $conditions['id']); } + if (isset($conditions['company_id'])) { + $this->model = $this->model->where('company_id', $conditions['company_id']); + } + + + if (isset($conditions['starttime'])) { + $this->model = $this->model->where('order_at', '>=', $conditions['starttime']); + } + + if (isset($conditions['endtime'])) { + $this->model = $this->model->where('order_at', '<=', $conditions['endtime']); + } + return $this; } -} \ No newline at end of file +} diff --git a/app/Domains/Virtual/Services/AddedOrderService.php b/app/Domains/Virtual/Services/AddedOrderService.php new file mode 100644 index 00000000..a8703830 --- /dev/null +++ b/app/Domains/Virtual/Services/AddedOrderService.php @@ -0,0 +1,208 @@ +orderRepository = $orderRepository; + } + + /** + * 订单列表 + * + * @param array $conditions + * @return mixed + */ + public function paginate(array $conditions = []) + { + $limit = $conditions['limit'] ?? 35; + + $res = $this->orderRepository->with(['company:id,name','package:id,name,carrier_operator']) + ->withConditions($conditions)->applyConditions()->orderBy('order_at', 'desc')->paginate($limit); + + return $res; + } + + /** + * 订单计数 + * + * @param array $conditions + * @return mixed + */ + public function count(array $conditions = []) + { + $select = [ + DB::raw('COUNT(*) as total_count'), + DB::raw('SUM(custom_price) as total_price'), + DB::raw('SUM(custom_price*transaction_status) as transacted_price'), + ]; + + $res = $this->orderRepository->select($select)->withConditions($conditions)->applyConditions()->first()->toArray(); + + $res['total_price'] = $res['total_price'] ?: 0; + $res['transacted_price'] = $res['transacted_price'] ?: 0; + unset($res['company']); + unset($res['package']); + + return $res; + } + + /** + * 下单 + * + * @param array $attributes + * @return Order + */ + public function store(array $attributes = []) + { + $attributes['sn'] = $attributes['sn'] ?: $this->generateSn(); + + $rule = [ + 'company_id' => ['exists:virtual_companies,id'], + 'product_id' => [], + 'counts' => [], + 'pay_channel' => [Rule::in(array_collapse(app(Dicts::class)->get('pay_channel')))], + 'contacts' => ['display_length:2,32'], + 'mobile' => ['cn_phone'], + 'area' => ['max:255'], + 'address' => ['max:255'], + 'order_status' => ['in:0,1,2,3,4'], + 'transaction_status' => ['in:0,1,2'], + 'extends' => ['array'], + ]; + + $message = [ + 'company_id.required' => '请输入企业ID', + 'company_id.exists' => '企业不存在或已删除', + 'product_id.required' => '请选择套餐', + 'counts.required' => '请输入订购数量', + 'pay_channel.required' => '请选择支付方式', + 'pay_channel.in' => '支付方式不合法', + 'contacts.required' => '联系人不能为空', + 'contacts.display_length' => '联系人名称长度不合法', + 'mobile.required' => '手机号不能为空', + 'mobile.cn_phone' => '手机号不合法', + 'area.required' => '请选择区域', + 'address.required' => '请输入详细地址', + ]; + + if (!$attributes['id']) { + $rule['company_id'][] = 'required'; + $rule['product_id'][] = 'required'; + $rule['counts'][] = 'required'; + $rule['pay_channel'][] = 'required'; + $rule['contacts'][] = 'required'; + $rule['mobile'][] = 'required'; + $rule['area'][] = 'required'; + $rule['address'][] = 'required'; + } + + Validator::validate($attributes, $rule, $message); + + if (!$attributes['id']) { + if (!$product = app(ProductRepository::class)->withConditions(['id' => $attributes['product_id']])->first()) { + throw new NotExistException('套餐不存在或已删除'); + } + + if ($product->company_id != $attributes['company_id']) { + throw new NotAllowedException('非法操作'); + } + + $attributes['unit_price'] = $product->base_price; + $attributes['total_price'] = $attributes['unit_price'] * $attributes['counts']; + $attributes['custom_price'] = $attributes['unit_price'] * $attributes['counts']; + $attributes['order_at'] = $attributes['order_at'] ?? date('Y-m-d H:i:s'); + $attributes['package_id'] = $attributes['package_id'] ?? $product->package_id; + + $node = $this->orderRepository->create($attributes); + } + + if ($attributes['id']) { + if (!$node = $this->orderRepository->find($attributes['id'])) { + throw new NotExistException('订单不存在或已删除'); + } + + if (!empty($attributes['extends']) && is_array($attributes['extends'])) { + $attributes['extends'] = array_merge($node->extends ?: [], $attributes['extends']); + } + + $this->orderRepository->setModel($node)->update($attributes); + } + + return $node; + } + + /** + * 取消订单 + * + * @return bool + */ + public function cancel($id) + { + if (!$node = $this->orderRepository->find($id)) { + throw new NotExistException('订单不存在或已删除'); + } + + if ($node->order_status !== 0) { + throw new NotExistException('订单已出库,不能取消'); + } + + if ($node->transaction_status !== 0) { + throw new NotExistException('订单已付款,不能取消'); + } + + $this->orderRepository->setModel($node)->update(['order_status' => 1]); + + return $node; + } + + /** + * 确认收货 + * + * @return bool + */ + public function received($id) + { + if (!$node = $this->orderRepository->find($id)) { + throw new NotExistException('订单不存在或已删除'); + } + + if ($node->order_status !== 3) { + throw new NotExistException('订单未发货,不能修改'); + } + + $this->orderRepository->setModel($node)->update(['order_status' => 4]); + + return $node; + } + + /** + * 生成订单编号 + * + * @return void + */ + public function generateSn() + { + return date('YmdHis') . explode('.', microtime(true))[1] . sprintf('%02d', rand(0, 99)); + } +} diff --git a/app/Models/Real/OrderCard.php b/app/Models/Real/OrderCard.php index 069d4a26..ec083778 100644 --- a/app/Models/Real/OrderCard.php +++ b/app/Models/Real/OrderCard.php @@ -29,31 +29,31 @@ class OrderCard extends Model // 续费套餐 public function renewalPackages() { - return $this->belongsToMany(Package::class, 'real_package_renewal_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'real_added_order_renewal_cards', 'sim', 'package_id'); } // 续费包套餐 public function renewalPackagePackages() { - return $this->belongsToMany(Package::class, 'real_package_renewal_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'real_added_order_renewal_package_cards', 'sim', 'package_id'); } // 加油包套餐 public function flowPackagePackages() { - return $this->belongsToMany(Package::class, 'real_package_flows_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'real_added_order_flows_package_cards', 'sim', 'package_id'); } // 可选包套餐 public function optionalPackagePackages() { - return $this->belongsToMany(Package::class, 'real_package_optional_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'real_added_order_optional_package_cards', 'sim', 'package_id'); } // 附加包套餐 public function additionalPackagePackages() { - return $this->belongsToMany(Package::class, 'real_package_additional_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'real_added_order_additional_package_cards', 'sim', 'package_id'); } // 续费订单 diff --git a/app/Models/Virtual/OrderCard.php b/app/Models/Virtual/OrderCard.php index ff2d5b3e..aa6b8b86 100644 --- a/app/Models/Virtual/OrderCard.php +++ b/app/Models/Virtual/OrderCard.php @@ -29,31 +29,31 @@ class OrderCard extends Model // 续费套餐 public function renewalPackages() { - return $this->belongsToMany(Package::class, 'virtual_package_renewal_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'virtual_added_order_renewal_cards', 'sim', 'package_id'); } // 续费包套餐 public function renewalPackagePackages() { - return $this->belongsToMany(Package::class, 'virtual_package_renewal_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'virtual_added_order_renewal_package_cards', 'sim', 'package_id'); } // 加油包套餐 public function flowPackagePackages() { - return $this->belongsToMany(Package::class, 'virtual_package_flows_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'virtual_added_order_flows_package_cards', 'sim', 'package_id'); } // 可选包套餐 public function optionalPackagePackages() { - return $this->belongsToMany(Package::class, 'virtual_package_optional_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'virtual_added_order_optional_package_cards', 'sim', 'package_id'); } // 附加包套餐 public function additionalPackagePackages() { - return $this->belongsToMany(Package::class, 'virtual_package_additional_package_cards', 'sim', 'package_id'); + return $this->belongsToMany(Package::class, 'virtual_added_order_additional_package_cards', 'sim', 'package_id'); } // 续费订单 diff --git a/composer.lock b/composer.lock index a5862e77..21111296 100644 --- a/composer.lock +++ b/composer.lock @@ -626,17 +626,17 @@ }, { "name": "dipper/foundation", - "version": "1.1.9", + "version": "1.1.13", "source": { "type": "git", "url": "ssh://gogs@git.fxft.net:2222/composer/foundation.git", - "reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0" + "reference": "7fa8390645a5cd52bc68666a9af9d8b008860200" }, "dist": { "type": "tar", - "url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.9-51f1b8.tar", - "reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0", - "shasum": "b17959dd9990df31f7e6c3cff53749afe151f670" + "url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.13-c3e049.tar", + "reference": "7fa8390645a5cd52bc68666a9af9d8b008860200", + "shasum": "e8c31e9bf07ea46e491c969a83465fc969f7e96e" }, "require": { "barryvdh/laravel-cors": "~0.11", @@ -670,7 +670,7 @@ } ], "description": "The Foundation of the Dipper Architecture project for Lumen", - "time": "2018-12-21T07:43:51+00:00" + "time": "2018-12-24T06:42:58+00:00" }, { "name": "dipper/jwt-auth", diff --git a/database/migrations/2018_11_16_190020_create_failed_jobs_table.php b/database/migrations/2018_11_16_190020_create_failed_jobs_table.php index 54e7d59f..f047be65 100644 --- a/database/migrations/2018_11_16_190020_create_failed_jobs_table.php +++ b/database/migrations/2018_11_16_190020_create_failed_jobs_table.php @@ -13,6 +13,10 @@ class CreateFailedJobsTable extends Migration */ public function up() { + if (Schema::hasTable('failed_jobs')) { + return; + } + Schema::create('failed_jobs', function (Blueprint $table) { $table->bigIncrements('id'); $table->text('connection'); diff --git a/database/migrations/2018_11_27_175137_create_base_tables.php b/database/migrations/2018_11_27_175137_create_base_tables.php deleted file mode 100644 index c3a1b68a..00000000 --- a/database/migrations/2018_11_27_175137_create_base_tables.php +++ /dev/null @@ -1,234 +0,0 @@ -get('tables') as $prefix => $type) { - Schema::create("{$prefix}_companies", function (Blueprint $table) use ($type) { - $table->increments('id')->comment('企业ID'); - $table->string('sn', 32)->comment('企业编号'); - $table->string('name', 32)->default('')->comment('企业名称'); - $table->string('contacts', 20)->default('')->comment('联系人'); - $table->string('mobile', 20)->default('')->comment('手机号'); - $table->string('address')->default('')->comment('地址'); - $table->text('remark')->nullable()->comment('订单备注'); - $table->text('extends')->nullable()->comment('扩展信息'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sn', 'deleted_at']); - $table->comment("{$type}企业"); - }); - - Schema::create("{$prefix}_packages", function (Blueprint $table) use ($type) { - $table->increments('id')->comment('企业ID'); - $table->integer('parent_id')->unsigned()->default(0)->comment('父级ID'); - $table->string('sn', 20)->comment('套餐编号'); - $table->string('name', 32)->comment('套餐名称'); - $table->tinyInteger('type')->unsigned()->default(255)->comment('套餐类型(0:基础套餐 1:续费包 2:加油包 3:可选包 4:附加包)'); - $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); - $table->integer('cost_price')->unsigned()->default(0)->comment('成本价格'); - $table->integer('guide_price')->unsigned()->default(0)->comment('指导价格'); - $table->integer('renewal_cost_price')->unsigned()->default(0)->comment('续费成本价格'); - $table->integer('renewal_guide_price')->unsigned()->default(0)->comment('续费指导价格'); - $table->integer('flows')->unsigned()->default(0)->comment('套餐流量(M)'); - $table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)'); - $table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)'); - $table->tinyInteger('has_messages')->unsigned()->default(255)->comment('是否开通短信服务(0:无 1:有)'); - $table->tinyInteger('has_lbs')->unsigned()->default(255)->comment('是否开通LBS服务(0:无 1:有)'); - $table->tinyInteger('reset_months')->unsigned()->default(0)->comment('重置周期(月)'); - $table->tinyInteger('service_months')->unsigned()->default(0)->comment('套餐周期(月)'); - $table->tinyInteger('effect_months')->unsigned()->default(0)->comment('生效延迟周期(月)'); - $table->tinyInteger('delay_months')->unsigned()->default(0)->comment('服务延长周期(月)'); - $table->text('description')->nullable()->comment('描述'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sn', 'deleted_at']); - $table->index('name'); - $table->index('parent_id'); - $table->index('type'); - $table->index('carrier_operator'); - - $table->comment("{$type}套餐"); - }); - - Schema::create("{$prefix}_order_cards", function (Blueprint $table) use ($type) { - $table->increments('id')->comment('关联表ID'); - $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); - $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); - $table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业ID"); - $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sim', 'order_id']); - $table->unique(['sim', 'deleted_at']); - - $table->comment("{$type}订单企业套餐卡关联表"); - }); - - Schema::create("{$prefix}_added_orders", function (Blueprint $table) use ($type) { - $table->increments('id')->comment('订单ID'); - $table->string('sn', 32)->comment('订单编号'); - $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)'); - $table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业ID"); - $table->string('transaction_no', 64)->comment('交易流水号'); - $table->string('pay_channel', 20)->default('')->comment('支付频道'); - $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); - $table->integer('counts')->unsigned()->default(0)->comment('数量'); - $table->integer('total_price')->unsigned()->default(0)->comment('总价'); - $table->timestamp('order_at')->nullable()->comment('下单时间'); - $table->text('remark')->nullable()->comment('订单备注'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sn', 'deleted_at']); - $table->index('type'); - $table->index('company_id'); - $table->index('order_at'); - - $table->comment("{$type}增值包订单"); - }); - } - - Schema::create("real_orders", function (Blueprint $table) { - $table->increments('id')->comment('订单ID'); - $table->string('sn', 32)->comment('订单编号'); - $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐)'); - $table->integer('company_id')->unsigned()->default(0)->comment("企业ID"); - $table->string('transaction_no', 64)->comment('交易流水号'); - $table->string('pay_channel', 20)->default('')->comment('支付频道'); - $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); - $table->integer('counts')->unsigned()->default(0)->comment('数量'); - $table->integer('total_price')->unsigned()->default(0)->comment('总价'); - $table->timestamp('order_at')->nullable()->comment('下单时间'); - $table->string('address')->default('')->comment('收货地址'); - $table->string('contacts')->default('')->comment('联系人'); - $table->string('mobile')->default('')->comment('电话'); - $table->text('logistics_remark')->nullable()->comment('物流备注'); - $table->text('remark')->nullable()->comment('订单备注'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sn', 'deleted_at']); - $table->index('type'); - $table->index('company_id'); - $table->index('order_at'); - - $table->comment('RD订单'); - }); - - Schema::create("blocs", function (Blueprint $table) { - $table->increments('id')->comment('集团ID'); - $table->string('sn', 32)->comment('集团编号'); - $table->string('name', 32)->comment('集团名称'); - $table->string('shorthand', 32)->comment('英文简称'); - $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sn', 'deleted_at']); - $table->index('name'); - $table->index('carrier_operator'); - - $table->comment('卡源集团'); - }); - - Schema::create("cards", function (Blueprint $table) { - $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); - $table->string('imsi', 32)->default('')->comment('imsi号'); - $table->string('iccid', 32)->default('')->comment('iccid号'); - $table->integer('bloc_id')->unsigned()->default(0)->comment('来源集团ID'); - $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); - $table->timestamp('activate_at')->nullable()->comment('激活时间'); - $table->timestamp('virtual_activate_at')->nullable()->comment('虚拟激活时间'); - $table->tinyInteger('type')->unsigned()->default(0)->comment('类型(0:真实卡 1:虚拟卡)'); - $table->timestamps(); - - $table->primary('sim'); - $table->comment('卡基础信息表'); - }); - - Schema::create("virtual_company_accounts", function (Blueprint $table) { - $table->increments('id')->comment('自增ID'); - $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); - $table->string('nickname', 32)->default('')->comment('昵称'); - $table->string('mobile', 20)->default('')->comment('手机号'); - $table->string('username', 32)->default('')->comment('登录名'); - $table->string('password', 32)->default('')->comment('密码'); - $table->string('salt', 6)->default('')->comment('盐'); - $table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0未激活 1正常 2禁用'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['mobile', 'deleted_at']); - $table->comment('VD企业账号表'); - }); - - Schema::create("virtual_company_addresses", function (Blueprint $table) { - $table->increments('id')->comment('自增ID'); - $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); - $table->string('contacts', 20)->default('')->comment('联系人'); - $table->string('mobile', 20)->default('')->comment('手机号'); - $table->string('area')->default('')->comment('区域'); - $table->string('address')->default('')->comment('地址'); - $table->tinyInteger('default')->unsigned()->default(0)->comment('是否默认 0:不是 1:是'); - $table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用'); - $table->timestamps(); - $table->softDeletes(); - - $table->comment('VD企业收货地址表'); - }); - - Schema::create("virtual_products", function (Blueprint $table) { - $table->increments('id')->comment('自增ID'); - $table->string('sn', 32)->comment('产品编码'); - $table->string('name', 32)->comment('产品名称'); - $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); - $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); - $table->integer('base_price')->unsigned()->default(0)->comment('基础价格'); - $table->integer('renewal_price')->unsigned()->default(0)->comment('续费价格'); - $table->text('remark')->nullable()->comment('备注'); - $table->timestamps(); - $table->softDeletes(); - - $table->unique(['sn', 'deleted_at']); - - $table->comment('VD企业定价表'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - foreach (app(Dicts::class)->get('tables') as $prefix => $type) { - Schema::dropIfExists("{$prefix}_added_orders"); - Schema::dropIfExists("{$prefix}_orders"); - Schema::dropIfExists("{$prefix}_order_cards"); - Schema::dropIfExists("{$prefix}_packages"); - Schema::dropIfExists("{$prefix}_companies"); - } - - Schema::dropIfExists("cards"); - Schema::dropIfExists("blocs"); - Schema::dropIfExists("virtual_products"); - Schema::dropIfExists("virtual_company_addresses"); - Schema::dropIfExists("virtual_company_accounts"); - } -} diff --git a/database/migrations/2018_11_27_175146_create_order_tables.php b/database/migrations/2018_11_27_175146_create_order_tables.php deleted file mode 100644 index ad2b889e..00000000 --- a/database/migrations/2018_11_27_175146_create_order_tables.php +++ /dev/null @@ -1,61 +0,0 @@ - '卡关联可选包订单', - 'added_order_renewal_package_cards' => '卡关联加油包订单', - 'added_order_flows_package_cards' => '卡关联续费包订单', - 'added_order_optional_package_cards' => '卡关联续费订单', - 'added_order_additional_package_cards' => '卡关联基础订单', - ]; - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - foreach (app(Dicts::class)->get('tables') as $prefix => $type) { - foreach ($this->tables as $table_name => $table_comment) { - $table_name = $prefix . '_' . $table_name; - $table_comment = $type . $table_comment; - Schema::create($table_name, function (Blueprint $table) use ($prefix, $table_comment) { - $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); - $table->bigInteger('sim')->unsigned()->default(0)->comment('SIM卡号'); - - if ($prefix === 'virtual') { - $table->integer('company_id')->unsigned()->default(0)->comment("企业ID"); - $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); - } - - $table->integer('counts')->unsigned()->default(1)->comment('数量'); - $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); - $table->primary(['order_id', 'sim']); - $table->comment($table_comment); - }); - } - } - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - foreach (app(Dicts::class)->get('tables') as $prefix => $type) { - foreach ($this->tables as $table_name => $table_comment) { - $table_name = $prefix . '_' . $table_name; - Schema::dropIfExists($table_name); - } - } - } -} diff --git a/database/migrations/2018_11_27_175152_create_package_tables.php b/database/migrations/2018_11_27_175152_create_package_tables.php deleted file mode 100644 index 0268247a..00000000 --- a/database/migrations/2018_11_27_175152_create_package_tables.php +++ /dev/null @@ -1,46 +0,0 @@ - '卡关联续费套餐', - 'real_package_renewal_package_cards' => '卡关联续费包套餐', - 'real_package_flows_package_cards' => '卡关联加油包套餐', - 'real_package_optional_package_cards' => '卡关联可选包套餐', - 'real_package_additional_package_cards' => '卡关联附加套餐', - ]; - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - foreach ($this->tables as $table_name => $table_comment) { - Schema::create($table_name, function (Blueprint $table) use ($table_comment) { - $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); - $table->bigInteger('sim')->unsigned()->default(0)->comment('SIM卡号'); - $table->primary(['package_id', 'sim']); - $table->comment($table_comment); - }); - } - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - foreach ($this->tables as $table_name => $table_comment) { - Schema::dropIfExists($table_name); - } - } -} diff --git a/database/migrations/2018_12_24_164210_create_blocs_table.php b/database/migrations/2018_12_24_164210_create_blocs_table.php new file mode 100644 index 00000000..be3731b0 --- /dev/null +++ b/database/migrations/2018_12_24_164210_create_blocs_table.php @@ -0,0 +1,46 @@ +increments('id')->comment('集团ID'); + $table->string('sn', 32)->comment('集团编号'); + $table->string('name', 32)->comment('集团名称'); + $table->string('shorthand', 32)->comment('英文简称'); + $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->index('name'); + $table->index('carrier_operator'); + + $table->comment('卡源集团'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('blocs'); + } +} diff --git a/database/migrations/2018_12_24_164218_create_cards_table.php b/database/migrations/2018_12_24_164218_create_cards_table.php new file mode 100644 index 00000000..dc464ff5 --- /dev/null +++ b/database/migrations/2018_12_24_164218_create_cards_table.php @@ -0,0 +1,45 @@ +bigInteger('sim')->unsigned()->default(0)->comment('sim号'); + $table->string('imsi', 32)->default('')->comment('imsi号'); + $table->string('iccid', 32)->default('')->comment('iccid号'); + $table->integer('bloc_id')->unsigned()->default(0)->comment('来源集团ID'); + $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); + $table->timestamp('activate_at')->nullable()->comment('激活时间'); + $table->timestamp('virtual_activate_at')->nullable()->comment('虚拟激活时间'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('类型(0:真实卡 1:虚拟卡)'); + $table->timestamps(); + + $table->primary('sim'); + $table->comment('卡基础信息表'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('cards'); + } +} diff --git a/database/migrations/2018_12_24_164318_create_real_companies_table.php b/database/migrations/2018_12_24_164318_create_real_companies_table.php new file mode 100644 index 00000000..fb170c7d --- /dev/null +++ b/database/migrations/2018_12_24_164318_create_real_companies_table.php @@ -0,0 +1,46 @@ +increments('id')->comment('企业ID'); + $table->string('sn', 32)->comment('企业编号'); + $table->string('name', 32)->default('')->comment('企业名称'); + $table->string('contacts', 20)->default('')->comment('联系人'); + $table->string('mobile', 20)->default('')->comment('手机号'); + $table->string('address')->default('')->comment('地址'); + $table->text('remark')->nullable()->comment('订单备注'); + $table->text('extends')->nullable()->comment('扩展信息'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->comment("RD企业"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('real_companies'); + } +} diff --git a/database/migrations/2018_12_24_164423_create_real_packages_table.php b/database/migrations/2018_12_24_164423_create_real_packages_table.php new file mode 100644 index 00000000..0314fdf4 --- /dev/null +++ b/database/migrations/2018_12_24_164423_create_real_packages_table.php @@ -0,0 +1,63 @@ +increments('id')->comment('企业ID'); + $table->integer('parent_id')->unsigned()->default(0)->comment('父级ID'); + $table->string('sn', 20)->comment('套餐编号'); + $table->string('name', 32)->comment('套餐名称'); + $table->tinyInteger('type')->unsigned()->default(255)->comment('套餐类型(0:基础套餐 1:续费包 2:加油包 3:可选包 4:附加包)'); + $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); + $table->integer('cost_price')->unsigned()->default(0)->comment('成本价格'); + $table->integer('guide_price')->unsigned()->default(0)->comment('指导价格'); + $table->integer('renewal_cost_price')->unsigned()->default(0)->comment('续费成本价格'); + $table->integer('renewal_guide_price')->unsigned()->default(0)->comment('续费指导价格'); + $table->integer('flows')->unsigned()->default(0)->comment('套餐流量(M)'); + $table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)'); + $table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)'); + $table->tinyInteger('has_messages')->unsigned()->default(255)->comment('是否开通短信服务(0:无 1:有)'); + $table->tinyInteger('has_lbs')->unsigned()->default(255)->comment('是否开通LBS服务(0:无 1:有)'); + $table->tinyInteger('reset_months')->unsigned()->default(0)->comment('重置周期(月)'); + $table->tinyInteger('service_months')->unsigned()->default(0)->comment('套餐周期(月)'); + $table->tinyInteger('effect_months')->unsigned()->default(0)->comment('生效延迟周期(月)'); + $table->tinyInteger('delay_months')->unsigned()->default(0)->comment('服务延长周期(月)'); + $table->text('description')->nullable()->comment('描述'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->index('name'); + $table->index('parent_id'); + $table->index('type'); + $table->index('carrier_operator'); + + $table->comment("RD套餐"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('real_packages'); + } +} diff --git a/database/migrations/2018_12_24_164430_create_real_orders_table.php b/database/migrations/2018_12_24_164430_create_real_orders_table.php new file mode 100644 index 00000000..ea1d5184 --- /dev/null +++ b/database/migrations/2018_12_24_164430_create_real_orders_table.php @@ -0,0 +1,57 @@ +increments('id')->comment('订单ID'); + $table->string('sn', 32)->comment('订单编号'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐)'); + $table->integer('company_id')->unsigned()->default(0)->comment("企业ID"); + $table->string('transaction_no', 64)->comment('交易流水号'); + $table->string('pay_channel', 20)->default('')->comment('支付频道'); + $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); + $table->integer('counts')->unsigned()->default(0)->comment('数量'); + $table->integer('total_price')->unsigned()->default(0)->comment('总价'); + $table->timestamp('order_at')->nullable()->comment('下单时间'); + $table->string('address')->default('')->comment('收货地址'); + $table->string('contacts')->default('')->comment('联系人'); + $table->string('mobile')->default('')->comment('电话'); + $table->text('logistics_remark')->nullable()->comment('物流备注'); + $table->text('remark')->nullable()->comment('订单备注'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->index('type'); + $table->index('company_id'); + $table->index('order_at'); + + $table->comment('RD订单'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('real_orders'); + } +} diff --git a/database/migrations/2018_12_24_164434_create_real_order_cards_table.php b/database/migrations/2018_12_24_164434_create_real_order_cards_table.php new file mode 100644 index 00000000..ed970966 --- /dev/null +++ b/database/migrations/2018_12_24_164434_create_real_order_cards_table.php @@ -0,0 +1,45 @@ +increments('id')->comment('关联表ID'); + $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); + $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'deleted_at']); + + $table->comment("RD订单企业套餐卡关联表"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('real_order_cards'); + } +} diff --git a/database/migrations/2018_12_24_164457_create_real_added_orders_table.php b/database/migrations/2018_12_24_164457_create_real_added_orders_table.php new file mode 100644 index 00000000..2c89e134 --- /dev/null +++ b/database/migrations/2018_12_24_164457_create_real_added_orders_table.php @@ -0,0 +1,53 @@ +increments('id')->comment('订单ID'); + $table->string('sn', 32)->comment('订单编号'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->string('transaction_no', 64)->comment('交易流水号'); + $table->string('pay_channel', 20)->default('')->comment('支付频道'); + $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); + $table->integer('counts')->unsigned()->default(0)->comment('数量'); + $table->integer('total_price')->unsigned()->default(0)->comment('总价'); + $table->timestamp('order_at')->nullable()->comment('下单时间'); + $table->text('remark')->nullable()->comment('订单备注'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->index('type'); + $table->index('company_id'); + $table->index('order_at'); + + $table->comment("RD增值包订单"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('real_added_orders'); + } +} diff --git a/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php b/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php new file mode 100644 index 00000000..7ffd5971 --- /dev/null +++ b/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php @@ -0,0 +1,53 @@ + 'RD卡关联基础订单', + 'real_added_order_renewal_package_cards' => 'RD卡关联续费包订单', + 'real_added_order_flows_package_cards' => 'RD卡关联加油包订单', + 'real_added_order_optional_package_cards' => 'RD卡关联可选包订单', + 'real_added_order_additional_package_cards' => 'RD卡关联附加包订单', + ]; + + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + foreach ($this->tables as $table_name => $table_comment) { + if (Schema::hasTable($table_name)) { + continue; + } + + Schema::create($table_name, function (Blueprint $table) use ($table_comment) { + $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); + $table->bigInteger('sim')->unsigned()->default(0)->comment('SIM卡号'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->integer('counts')->unsigned()->default(1)->comment('数量'); + $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); + $table->primary(['order_id', 'sim']); + $table->comment($table_comment); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + foreach ($this->tables as $table_name => $table_comment) { + Schema::dropIfExists($table_name); + } + } +} diff --git a/database/migrations/2018_12_24_164716_create_virtual_companies_table.php b/database/migrations/2018_12_24_164716_create_virtual_companies_table.php new file mode 100644 index 00000000..cdf7a8c9 --- /dev/null +++ b/database/migrations/2018_12_24_164716_create_virtual_companies_table.php @@ -0,0 +1,46 @@ +increments('id')->comment('企业ID'); + $table->string('sn', 32)->comment('企业编号'); + $table->string('name', 32)->default('')->comment('企业名称'); + $table->string('contacts', 20)->default('')->comment('联系人'); + $table->string('mobile', 20)->default('')->comment('手机号'); + $table->string('address')->default('')->comment('地址'); + $table->text('remark')->nullable()->comment('订单备注'); + $table->text('extends')->nullable()->comment('扩展信息'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->comment("VD企业"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_companies'); + } +} diff --git a/database/migrations/2018_12_24_164722_create_virtual_packages_table.php b/database/migrations/2018_12_24_164722_create_virtual_packages_table.php new file mode 100644 index 00000000..68c6d8d3 --- /dev/null +++ b/database/migrations/2018_12_24_164722_create_virtual_packages_table.php @@ -0,0 +1,63 @@ +increments('id')->comment('企业ID'); + $table->integer('parent_id')->unsigned()->default(0)->comment('父级ID'); + $table->string('sn', 20)->comment('套餐编号'); + $table->string('name', 32)->comment('套餐名称'); + $table->tinyInteger('type')->unsigned()->default(255)->comment('套餐类型(0:基础套餐 1:续费包 2:加油包 3:可选包 4:附加包)'); + $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)'); + $table->integer('cost_price')->unsigned()->default(0)->comment('成本价格'); + $table->integer('guide_price')->unsigned()->default(0)->comment('指导价格'); + $table->integer('renewal_cost_price')->unsigned()->default(0)->comment('续费成本价格'); + $table->integer('renewal_guide_price')->unsigned()->default(0)->comment('续费指导价格'); + $table->integer('flows')->unsigned()->default(0)->comment('套餐流量(M)'); + $table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)'); + $table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)'); + $table->tinyInteger('has_messages')->unsigned()->default(255)->comment('是否开通短信服务(0:无 1:有)'); + $table->tinyInteger('has_lbs')->unsigned()->default(255)->comment('是否开通LBS服务(0:无 1:有)'); + $table->tinyInteger('reset_months')->unsigned()->default(0)->comment('重置周期(月)'); + $table->tinyInteger('service_months')->unsigned()->default(0)->comment('套餐周期(月)'); + $table->tinyInteger('effect_months')->unsigned()->default(0)->comment('生效延迟周期(月)'); + $table->tinyInteger('delay_months')->unsigned()->default(0)->comment('服务延长周期(月)'); + $table->text('description')->nullable()->comment('描述'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->index('name'); + $table->index('parent_id'); + $table->index('type'); + $table->index('carrier_operator'); + + $table->comment("VD套餐"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_packages'); + } +} diff --git a/database/migrations/2018_12_24_164728_create_virtual_company_accounts_table.php b/database/migrations/2018_12_24_164728_create_virtual_company_accounts_table.php new file mode 100644 index 00000000..66b842c9 --- /dev/null +++ b/database/migrations/2018_12_24_164728_create_virtual_company_accounts_table.php @@ -0,0 +1,46 @@ +increments('id')->comment('自增ID'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->string('nickname', 32)->default('')->comment('昵称'); + $table->string('mobile', 20)->default('')->comment('手机号'); + $table->string('username', 32)->default('')->comment('登录名'); + $table->string('password', 32)->default('')->comment('密码'); + $table->string('salt', 6)->default('')->comment('盐'); + $table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0未激活 1正常 2禁用'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['mobile', 'deleted_at']); + $table->comment('VD企业账号表'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_company_accounts'); + } +} diff --git a/database/migrations/2018_12_24_164735_create_virtual_company_addresses_table.php b/database/migrations/2018_12_24_164735_create_virtual_company_addresses_table.php new file mode 100644 index 00000000..94ab3b78 --- /dev/null +++ b/database/migrations/2018_12_24_164735_create_virtual_company_addresses_table.php @@ -0,0 +1,45 @@ +increments('id')->comment('自增ID'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->string('contacts', 20)->default('')->comment('联系人'); + $table->string('mobile', 20)->default('')->comment('手机号'); + $table->string('area')->default('')->comment('区域'); + $table->string('address')->default('')->comment('地址'); + $table->tinyInteger('default')->unsigned()->default(0)->comment('是否默认 0:不是 1:是'); + $table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用'); + $table->timestamps(); + $table->softDeletes(); + + $table->comment('VD企业收货地址表'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_company_addresses'); + } +} diff --git a/database/migrations/2018_12_24_164742_create_virtual_products_table.php b/database/migrations/2018_12_24_164742_create_virtual_products_table.php new file mode 100644 index 00000000..0d36fd6f --- /dev/null +++ b/database/migrations/2018_12_24_164742_create_virtual_products_table.php @@ -0,0 +1,47 @@ +increments('id')->comment('自增ID'); + $table->string('sn', 32)->comment('产品编码'); + $table->string('name', 32)->comment('产品名称'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->integer('base_price')->unsigned()->default(0)->comment('基础价格'); + $table->integer('renewal_price')->unsigned()->default(0)->comment('续费价格'); + $table->text('remark')->nullable()->comment('备注'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + + $table->comment('VD企业定价表'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_products'); + } +} diff --git a/database/migrations/2018_12_12_170419_create_virtual_orders_table.php b/database/migrations/2018_12_24_164779_create_virtual_orders_table.php similarity index 87% rename from database/migrations/2018_12_12_170419_create_virtual_orders_table.php rename to database/migrations/2018_12_24_164779_create_virtual_orders_table.php index c634e37f..e66d0900 100644 --- a/database/migrations/2018_12_12_170419_create_virtual_orders_table.php +++ b/database/migrations/2018_12_24_164779_create_virtual_orders_table.php @@ -13,19 +13,23 @@ class CreateVirtualOrdersTable extends Migration */ public function up() { + if (Schema::hasTable('virtual_orders')) { + return; + } + Schema::create("virtual_orders", function (Blueprint $table) { $table->increments('id')->comment('订单ID'); $table->string('sn', 32)->comment('订单编号'); - $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐)'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:用户订单 1:后台订单)'); $table->integer('company_id')->unsigned()->default(0)->comment("企业ID"); - $table->integer('package_id')->unsigned()->default(0)->after('company_id')->comment('套餐ID'); - $table->integer('product_id')->unsigned()->default(0)->after('package_id')->comment('定价ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->integer('product_id')->unsigned()->default(0)->comment('定价ID'); $table->string('transaction_no', 64)->default('')->comment('交易流水号'); $table->string('pay_channel', 20)->default('')->comment('支付频道'); $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); $table->integer('counts')->unsigned()->default(0)->comment('数量'); $table->integer('total_price')->unsigned()->default(0)->comment('总价'); - $table->integer('custom_price')->unsigned()->default(0)->after('total_price')->comment('自定义总价'); + $table->integer('custom_price')->unsigned()->default(0)->comment('自定义总价'); $table->timestamp('order_at')->nullable()->comment('下单时间'); $table->string('area')->default('')->comment('区域'); $table->string('address')->default('')->comment('收货地址'); @@ -33,8 +37,8 @@ class CreateVirtualOrdersTable extends Migration $table->string('mobile')->default('')->comment('电话'); $table->string('logistics_company', '20')->default('')->comment('物流公司'); $table->string('logistics_no', 64)->default('')->comment('物流单号'); - $table->tinyInteger('order_status')->unsigned()->default(0)->after('mobile')->comment('订单状态(0:已下单 1:已取消 2:已出库 3:已发货 4:已签收)'); - $table->tinyInteger('transaction_status')->unsigned()->default(0)->after('order_status')->comment('收款状态(0:未收款 1:已收款 2:已退款)'); + $table->tinyInteger('order_status')->unsigned()->default(0)->comment('订单状态(0:已下单 1:已取消 2:已出库 3:已发货 4:已签收)'); + $table->tinyInteger('transaction_status')->unsigned()->default(0)->comment('收款状态(0:未收款 1:已收款 2:已退款)'); $table->text('logistics_remark')->nullable()->comment('物流备注'); $table->text('remark')->nullable()->comment('订单备注'); $table->text('extends')->nullable()->comment('扩展信息(cancel_remark:取消备注 refund_channel:退款频道 refund_account:退款账号 refund_remark:退款备注)'); @@ -47,6 +51,8 @@ class CreateVirtualOrdersTable extends Migration $table->index('order_at'); $table->comment('VD订单'); }); + + } /** diff --git a/database/migrations/2018_12_24_165555_create_virtual_order_cards_table.php b/database/migrations/2018_12_24_165555_create_virtual_order_cards_table.php new file mode 100644 index 00000000..03ba14de --- /dev/null +++ b/database/migrations/2018_12_24_165555_create_virtual_order_cards_table.php @@ -0,0 +1,45 @@ +increments('id')->comment('关联表ID'); + $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); + $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sim', 'order_id']); + $table->unique(['sim', 'deleted_at']); + + $table->comment("VD订单企业套餐卡关联表"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_order_cards'); + } +} diff --git a/database/migrations/2018_12_24_170936_create_virtual_added_orders_table.php b/database/migrations/2018_12_24_170936_create_virtual_added_orders_table.php new file mode 100644 index 00000000..635f64ef --- /dev/null +++ b/database/migrations/2018_12_24_170936_create_virtual_added_orders_table.php @@ -0,0 +1,54 @@ +increments('id')->comment('订单ID'); + $table->string('sn', 32)->comment('订单编号'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->string('transaction_no', 64)->comment('交易流水号'); + $table->string('pay_channel', 20)->default('')->comment('支付频道'); + $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); + $table->integer('counts')->unsigned()->default(0)->comment('数量'); + $table->integer('total_price')->unsigned()->default(0)->comment('总价'); + $table->integer('custom_price')->unsigned()->default(0)->comment('自定义总价'); + $table->timestamp('order_at')->nullable()->comment('下单时间'); + $table->text('remark')->nullable()->comment('订单备注'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['sn', 'deleted_at']); + $table->index('type'); + $table->index('company_id'); + $table->index('order_at'); + + $table->comment("VD增值包订单"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_added_orders'); + } +} diff --git a/database/migrations/2018_12_24_170946_create_virtual_added_order_cards_tables.php b/database/migrations/2018_12_24_170946_create_virtual_added_order_cards_tables.php new file mode 100644 index 00000000..0952b91b --- /dev/null +++ b/database/migrations/2018_12_24_170946_create_virtual_added_order_cards_tables.php @@ -0,0 +1,53 @@ + 'VD卡关联基础订单', + 'virtual_added_order_renewal_package_cards' => 'VD卡关联续费包订单', + 'virtual_added_order_flows_package_cards' => 'VD卡关联加油包订单', + 'virtual_added_order_optional_package_cards' => 'VD卡关联可选包订单', + 'virtual_added_order_additional_package_cards' => 'VD卡关联附加包订单', + ]; + + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + foreach ($this->tables as $table_name => $table_comment) { + if (Schema::hasTable($table_name)) { + continue; + } + + Schema::create($table_name, function (Blueprint $table) use ($table_comment) { + $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); + $table->bigInteger('sim')->unsigned()->default(0)->comment('SIM卡号'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->integer('counts')->unsigned()->default(1)->comment('数量'); + $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); + $table->primary(['order_id', 'sim']); + $table->comment($table_comment); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + foreach ($this->tables as $table_name => $table_comment) { + Schema::dropIfExists($table_name); + } + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index b8726a02..a89c7779 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -10,12 +10,25 @@ return array( 'ArithmeticError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php', 'AssertionError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php', 'CompanyAccountSeeder' => $baseDir . '/database/seeds/CompanyAccountSeeder.php', - 'CreateBaseTables' => $baseDir . '/database/migrations/2018_11_27_175137_create_base_tables.php', + 'CreateBlocsTable' => $baseDir . '/database/migrations/2018_12_24_164210_create_blocs_table.php', + 'CreateCardsTable' => $baseDir . '/database/migrations/2018_12_24_164218_create_cards_table.php', 'CreateFailedJobsTable' => $baseDir . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php', - 'CreateOrderTables' => $baseDir . '/database/migrations/2018_11_27_175146_create_order_tables.php', - 'CreatePackageTables' => $baseDir . '/database/migrations/2018_11_27_175152_create_package_tables.php', - 'CreateTestsTable' => $baseDir . '/database/migrations/2018_12_21_134548_create_tests_table.php', - 'CreateVirtualOrdersTable' => $baseDir . '/database/migrations/2018_12_12_170419_create_virtual_orders_table.php', + 'CreateRealAddedOrderCardsTables' => $baseDir . '/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php', + 'CreateRealAddedOrdersTable' => $baseDir . '/database/migrations/2018_12_24_164457_create_real_added_orders_table.php', + 'CreateRealCompaniesTable' => $baseDir . '/database/migrations/2018_12_24_164318_create_real_companies_table.php', + 'CreateRealOrderCardsTable' => $baseDir . '/database/migrations/2018_12_24_164434_create_real_order_cards_table.php', + 'CreateRealOrdersTable' => $baseDir . '/database/migrations/2018_12_24_164430_create_real_orders_table.php', + 'CreateRealPackageCardsTables' => $baseDir . '/database/migrations/2018_12_24_164462_create_real_package_cards_tables.php', + 'CreateRealPackagesTable' => $baseDir . '/database/migrations/2018_12_24_164423_create_real_packages_table.php', + 'CreateVirtualAddedOrderCardsTables' => $baseDir . '/database/migrations/2018_12_24_170946_create_virtual_added_order_cards_tables.php', + 'CreateVirtualAddedOrdersTable' => $baseDir . '/database/migrations/2018_12_24_170936_create_virtual_added_orders_table.php', + 'CreateVirtualCompaniesTable' => $baseDir . '/database/migrations/2018_12_24_164716_create_virtual_companies_table.php', + 'CreateVirtualCompanyAccountsTable' => $baseDir . '/database/migrations/2018_12_24_164728_create_virtual_company_accounts_table.php', + 'CreateVirtualCompanyAddressesTable' => $baseDir . '/database/migrations/2018_12_24_164735_create_virtual_company_addresses_table.php', + 'CreateVirtualOrderCardsTable' => $baseDir . '/database/migrations/2018_12_24_165555_create_virtual_order_cards_table.php', + 'CreateVirtualOrdersTable' => $baseDir . '/database/migrations/2018_12_24_164779_create_virtual_orders_table.php', + 'CreateVirtualPackagesTable' => $baseDir . '/database/migrations/2018_12_24_164722_create_virtual_packages_table.php', + 'CreateVirtualProductsTable' => $baseDir . '/database/migrations/2018_12_24_164742_create_virtual_products_table.php', 'DatabaseSeeder' => $baseDir . '/database/seeds/DatabaseSeeder.php', 'DivisionByZeroError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php', 'Error' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/Error.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index aa04e54b..db365bbb 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -713,12 +713,25 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9 'ArithmeticError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php', 'AssertionError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php', 'CompanyAccountSeeder' => __DIR__ . '/../..' . '/database/seeds/CompanyAccountSeeder.php', - 'CreateBaseTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175137_create_base_tables.php', + 'CreateBlocsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164210_create_blocs_table.php', + 'CreateCardsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164218_create_cards_table.php', 'CreateFailedJobsTable' => __DIR__ . '/../..' . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php', - 'CreateOrderTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175146_create_order_tables.php', - 'CreatePackageTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175152_create_package_tables.php', - 'CreateTestsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_21_134548_create_tests_table.php', - 'CreateVirtualOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_12_170419_create_virtual_orders_table.php', + 'CreateRealAddedOrderCardsTables' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php', + 'CreateRealAddedOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164457_create_real_added_orders_table.php', + 'CreateRealCompaniesTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164318_create_real_companies_table.php', + 'CreateRealOrderCardsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164434_create_real_order_cards_table.php', + 'CreateRealOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164430_create_real_orders_table.php', + 'CreateRealPackageCardsTables' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164462_create_real_package_cards_tables.php', + 'CreateRealPackagesTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164423_create_real_packages_table.php', + 'CreateVirtualAddedOrderCardsTables' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_170946_create_virtual_added_order_cards_tables.php', + 'CreateVirtualAddedOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_170936_create_virtual_added_orders_table.php', + 'CreateVirtualCompaniesTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164716_create_virtual_companies_table.php', + 'CreateVirtualCompanyAccountsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164728_create_virtual_company_accounts_table.php', + 'CreateVirtualCompanyAddressesTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164735_create_virtual_company_addresses_table.php', + 'CreateVirtualOrderCardsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_165555_create_virtual_order_cards_table.php', + 'CreateVirtualOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164779_create_virtual_orders_table.php', + 'CreateVirtualPackagesTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164722_create_virtual_packages_table.php', + 'CreateVirtualProductsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164742_create_virtual_products_table.php', 'DatabaseSeeder' => __DIR__ . '/../..' . '/database/seeds/DatabaseSeeder.php', 'DivisionByZeroError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php', 'Error' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/Error.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index a49d3cd9..883a272b 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -641,18 +641,18 @@ }, { "name": "dipper/foundation", - "version": "1.1.9", - "version_normalized": "1.1.9.0", + "version": "1.1.13", + "version_normalized": "1.1.13.0", "source": { "type": "git", "url": "ssh://gogs@git.fxft.net:2222/composer/foundation.git", - "reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0" + "reference": "7fa8390645a5cd52bc68666a9af9d8b008860200" }, "dist": { "type": "tar", - "url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.9-51f1b8.tar", - "reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0", - "shasum": "b17959dd9990df31f7e6c3cff53749afe151f670" + "url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.13-c3e049.tar", + "reference": "7fa8390645a5cd52bc68666a9af9d8b008860200", + "shasum": "e8c31e9bf07ea46e491c969a83465fc969f7e96e" }, "require": { "barryvdh/laravel-cors": "~0.11", @@ -667,7 +667,7 @@ "league/flysystem": "~1.0", "nesbot/carbon": "~1.21" }, - "time": "2018-12-21T07:43:51+00:00", + "time": "2018-12-24T06:42:58+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/dipper/foundation/src/Database/DatabaseServiceProvider.php b/vendor/dipper/foundation/src/Database/DatabaseServiceProvider.php index 048150b5..a9141149 100644 --- a/vendor/dipper/foundation/src/Database/DatabaseServiceProvider.php +++ b/vendor/dipper/foundation/src/Database/DatabaseServiceProvider.php @@ -177,7 +177,7 @@ class DatabaseServiceProvider extends ServiceProvider */ public function macroUpsert() { - return function (array $values, $filed = 'id') { + return function (array $values, $fields = ['id'], $doNoting = false) { if (empty($values)) { return false; } @@ -191,7 +191,7 @@ class DatabaseServiceProvider extends ServiceProvider } return $this->connection->affectingStatement( - $this->grammar->compileUpsert($this, $values, $filed), + $this->grammar->compileUpsert($this, $values, $fields, $doNoting), $this->cleanBindings(Arr::flatten($values, 1)) ); }; diff --git a/vendor/dipper/foundation/src/Database/MySqlGrammar.php b/vendor/dipper/foundation/src/Database/MySqlGrammar.php index 4754fc69..3c74feca 100644 --- a/vendor/dipper/foundation/src/Database/MySqlGrammar.php +++ b/vendor/dipper/foundation/src/Database/MySqlGrammar.php @@ -210,8 +210,12 @@ class MySqlGrammar extends Grammar * @param array|string $unique * @return string */ - public function compileUpsert(QueryBuilder $query, array $values, $filed = ['id']) + public function compileUpsert(QueryBuilder $query, array $values, $filed = ['id'], $doNothing = false) { + if ($doNothing) { + return $this->compileCreateOrIgnore($query, $values); + } + return $this->compileInsertUpdate($query, $values); } } diff --git a/vendor/dipper/foundation/src/Database/PostgresGrammar.php b/vendor/dipper/foundation/src/Database/PostgresGrammar.php index 19c8db59..3223a6fa 100644 --- a/vendor/dipper/foundation/src/Database/PostgresGrammar.php +++ b/vendor/dipper/foundation/src/Database/PostgresGrammar.php @@ -64,7 +64,7 @@ class PostgresGrammar extends Grammar * @param array|string $unique * @return string */ - public function compileUpsert(QueryBuilder $query, array $values, $fields = ['id']) + public function compileUpsert(QueryBuilder $query, array $values, $fields = ['id'], $doNothing = false) { $insert = $this->compileInsert($query, $values); @@ -98,6 +98,10 @@ class PostgresGrammar extends Grammar return "$insert on conflict ($reference) do nothing"; } + if ($doNothing) { + return "$insert on conflict ($reference) do nothing"; + } + $update = join(', ', array_map(function ($e) { return "\"$e\" = \"excluded\".\"$e\""; }, $excluded)); diff --git a/vendor/dipper/foundation/src/ServiceProvider.php b/vendor/dipper/foundation/src/ServiceProvider.php index 5cd98631..e8f135a9 100644 --- a/vendor/dipper/foundation/src/ServiceProvider.php +++ b/vendor/dipper/foundation/src/ServiceProvider.php @@ -140,6 +140,12 @@ class ServiceProvider extends BaseServiceProvider public function bootMacro() { Request::mixin(app(\Dipper\Foundation\Http\RequestMixin::class)); + + Collection::macro('collect', function () { + return $this->map(function ($value) { + return collect((array) $value); + }); + }); } /**