diff --git a/app/Domains/Real/Commands/Sync/AddedOrderSync.php b/app/Domains/Real/Commands/Sync/AddedOrderSync.php index 13a2b307..61714d47 100644 --- a/app/Domains/Real/Commands/Sync/AddedOrderSync.php +++ b/app/Domains/Real/Commands/Sync/AddedOrderSync.php @@ -153,7 +153,6 @@ class AddedOrderSync extends Command ->whereIn('account_no', array_keys($this->business_type)) ->where('create_time', '>=', $starttime->timestamp) ->where('create_time', '<=', $endtime->timestamp) - ->where('r_id', 112370) ->orderBy('create_time')->get()->collect()->toArray(); $array = []; diff --git a/app/Domains/Virtual/Http/Controllers/OrderController.php b/app/Domains/Virtual/Http/Controllers/OrderController.php index f36644cf..d36d6199 100644 --- a/app/Domains/Virtual/Http/Controllers/OrderController.php +++ b/app/Domains/Virtual/Http/Controllers/OrderController.php @@ -329,4 +329,20 @@ class OrderController extends Controller return res($order, '排单成功'); } + + /** + * 套餐升级. + * + * @return \Illuminate\Http\Response + */ + public function upgrade() + { + + + $attributes = $this->request->all(); + + $order = $this->orderService->upgrade($attributes); + + return res($order, '修改成功'); + } } diff --git a/app/Domains/Virtual/Services/OrderService.php b/app/Domains/Virtual/Services/OrderService.php index 324b86a0..66dc2084 100644 --- a/app/Domains/Virtual/Services/OrderService.php +++ b/app/Domains/Virtual/Services/OrderService.php @@ -924,6 +924,24 @@ class OrderService extends Service return $order; } + /** + * 套餐升级 + */ + public function upgrade(array $attributes = []) + { + $rule = [ + 'new_package_id' => ['required'], + 'selected' => ['required', 'array'], + ]; + + $message = [ + 'new_package_id.required' => '请选择新的套餐', + 'selected.required' => '请选择卡', + ]; + + Validator::validate($attributes, $rule, $message); + } + protected function upsertOrderCards($array, $node) { $table = $this->tables[$node['type']]; 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 index 4b10b05b..efe4e07e 100644 --- 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 @@ -26,7 +26,7 @@ class CreateRealOrderCardsTable extends Migration $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); $table->integer('counts')->unsigned()->default(0)->comment('数量'); $table->integer('unit_price')->unsigned()->default(0)->comment('单价'); - $table->integer('virtual_order_id')->unsigned()->default(0)->comment('VD 订单ID'); + $table->integer('virtual_order_id')->unsigned()->default(0)->comment('RD 订单ID'); $table->timestamp('refunded_at')->nullable()->comment('退货时间'); $table->timestamps(); $table->softDeletes(); @@ -45,22 +45,32 @@ class CreateRealOrderCardsTable extends Migration Schema::table('real_order_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id']); $table->unique(['sim', 'deleted_at']); + $table->comment("RD销售订单关联表"); }); Schema::table('real_order_renewal_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); + $table->comment("RD续费订单关联表"); }); Schema::table('real_order_renewal_package_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); + $table->comment("RD续费包订单关联表"); }); Schema::table('real_order_flows_package_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); + $table->comment("RD加油包订单关联表"); }); Schema::table('real_order_optional_package_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); + $table->comment("RD可选包订单关联表"); + }); + + Schema::table('real_order_additional_package_cards', function (Blueprint $table) { + $table->unique(['sim', 'order_id', 'deleted_at']); + $table->comment("RD附加包订单关联表"); }); } diff --git a/database/migrations/2018_12_31_165779_create_virtual_orders_table.php b/database/migrations/2018_12_31_165779_create_virtual_orders_table.php index 7b3bb7c0..24152cb0 100644 --- a/database/migrations/2018_12_31_165779_create_virtual_orders_table.php +++ b/database/migrations/2018_12_31_165779_create_virtual_orders_table.php @@ -21,7 +21,7 @@ class CreateVirtualOrdersTable extends Migration $table->increments('id')->comment('订单ID'); $table->string('sn', 32)->comment('订单编号'); $table->tinyInteger('source')->unsigned()->default(0)->comment('订单来源(0:用户订单 1:后台订单)'); - $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础订单 1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础订单 1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包 6:组合包 7:套餐升级)'); $table->integer('company_id')->unsigned()->default(0)->comment("企业ID"); $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); $table->string('transaction_no', 64)->default('')->comment('交易流水号'); diff --git a/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php b/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php index 5b34c212..5040cf92 100644 --- a/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php +++ b/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php @@ -49,24 +49,28 @@ class CreateVirtualOrderCardsTables extends Migration $table->unique(['sim', 'order_id', 'deleted_at']); $table->index(['type', 'company_id', 'package_id', 'unit_price']); $table->index(['service_start_at', 'service_end_at']); + $table->comment("VD销售订单关联表"); }); Schema::table('virtual_order_renewal_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); $table->index(['type', 'company_id', 'package_id', 'unit_price']); $table->index(['service_start_at', 'service_end_at']); + $table->comment("VD续费订单关联表"); }); Schema::table('virtual_order_renewal_package_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); $table->index(['type', 'company_id', 'package_id', 'unit_price']); $table->index(['service_start_at', 'service_end_at']); + $table->comment("VD续费包订单关联表"); }); Schema::table('virtual_order_flows_package_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); $table->index(['type', 'company_id', 'package_id', 'unit_price']); $table->index(['service_start_at', 'service_end_at']); + $table->comment("VD加油包订单关联表"); }); DB::unprepared(File::get(__DIR__ . '/create_virtual_order_cards_func.pgsql')); diff --git a/database/migrations/2019_04_17_161638_add_real_order_group_package_cards_partition.php b/database/migrations/2019_04_17_161638_add_real_order_group_package_cards_partition.php index b1c48d89..936d432f 100644 --- a/database/migrations/2019_04_17_161638_add_real_order_group_package_cards_partition.php +++ b/database/migrations/2019_04_17_161638_add_real_order_group_package_cards_partition.php @@ -19,6 +19,7 @@ class AddRealOrderGroupPackageCardsPartition extends Migration Schema::table('real_order_group_package_cards', function (Blueprint $table) { $table->unique(['sim', 'order_id', 'deleted_at']); + $table->comment("RD组合包订单关联表"); }); } diff --git a/database/migrations/2019_04_23_102650_add_virtual_order_upgrade_cards_partition.php b/database/migrations/2019_04_23_102650_add_virtual_order_upgrade_cards_partition.php new file mode 100644 index 00000000..6c9004dc --- /dev/null +++ b/database/migrations/2019_04_23_102650_add_virtual_order_upgrade_cards_partition.php @@ -0,0 +1,37 @@ +addPartition('virtual_order_upgrade_cards', 'list', [7]); + }); + + Schema::table('virtual_order_upgrade_cards', function (Blueprint $table) { + $table->unique(['sim', 'order_id', 'deleted_at']); + $table->index(['type', 'company_id', 'package_id', 'unit_price']); + $table->index(['service_start_at', 'service_end_at']); + $table->comment("VD升级订单关联表"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('virtual_order_upgrade_cards'); + } +} diff --git a/database/migrations/create_virtual_order_cards_func.pgsql b/database/migrations/create_virtual_order_cards_func.pgsql index ff66355f..381a16fd 100644 --- a/database/migrations/create_virtual_order_cards_func.pgsql +++ b/database/migrations/create_virtual_order_cards_func.pgsql @@ -25,39 +25,38 @@ CREATE OR REPLACE FUNCTION GET_TIMELINES(INT8[]) AS $$ DECLARE activate_cards JSONB := '[]'; + packages JSONB := '[]'; query TEXT; + package_row JSONB := '[]'; + orders JSON[] := '{}'; order_row RECORD; temp_service_start_at TIMESTAMP; temp_service_end_at TIMESTAMP; activated_at TIMESTAMP; BEGIN - RAISE NOTICE 't1'; SELECT array_to_json(array_agg(row_to_json(t))) INTO activate_cards - FROM (SELECT cards.sim, cards.virtual_activated_at FROM vd.cards WHERE cards.sim = ANY ($1)) t; - RAISE NOTICE 't2'; - query := 'SELECT - virtual_order_cards_partition.id, - virtual_order_cards_partition.type, - virtual_order_cards_partition.sim, - virtual_order_cards_partition.package_id, - virtual_order_cards_partition.created_at, - virtual_packages.service_months, - virtual_packages.effect_months, - virtual_packages.delay_months, - virtual_order_cards_partition.counts, - virtual_order_cards_partition.service_start_at, - virtual_order_cards_partition.service_end_at - FROM vd.virtual_order_cards_partition JOIN vd.virtual_packages ON virtual_order_cards_partition.package_id = virtual_packages."id" - WHERE virtual_order_cards_partition.sim = ANY($1) + FROM (SELECT cards.sim, cards.virtual_activated_at FROM vd.cards WHERE cards.sim = ANY ($1)) t; + + SELECT array_to_json(array_agg(row_to_json(t))) INTO packages + FROM (SELECT virtual_packages.id, virtual_packages.service_months, virtual_packages.effect_months, virtual_packages.effect_months FROM vd.virtual_packages) t; + + query := 'SELECT id, type, sim, package_id, created_at, counts, service_start_at, service_end_at + FROM vd.virtual_order_cards_partition + WHERE sim = ANY($1) ORDER BY sim ASC, created_at ASC'; + SELECT array_agg(row_to_json(t)) INTO orders + FROM EXECUTE query; + + + RAISE NOTICE '%s', orders; + + FOR order_row IN EXECUTE query USING $1 LOOP - RAISE NOTICE 't3'; SELECT value->>'virtual_activated_at' INTO activated_at - FROM json_array_elements(activate_cards::JSON) - WHERE value->>'sim' = order_row.sim::TEXT; - RAISE NOTICE 't4'; + FROM json_array_elements(activate_cards::JSON) + WHERE value->>'sim' = order_row.sim::TEXT; IF NOT FOUND THEN temp_service_start_at := NULL; @@ -66,22 +65,26 @@ BEGIN temp_service_start_at := NULL; temp_service_end_at := NULL; ELSE + SELECT value INTO package_row + FROM json_array_elements(packages::JSON) + WHERE value->>'id' = order_row.package_id::TEXT; + -- 服务时间 CASE (order_row."type") WHEN 0 THEN temp_service_start_at := TO_CHAR(activated_at, 'YYYY-MM-01 00:00:00'); - temp_service_end_at := temp_service_start_at + (order_row.service_months || ' month')::INTERVAL + - (order_row.delay_months || ' month')::INTERVAL - '1 second'::INTERVAL; + temp_service_end_at := temp_service_start_at + (package_row->>'service_months' || ' month')::INTERVAL + + (package_row->>'delay_months' || ' month')::INTERVAL - '1 second'::INTERVAL; WHEN 1, 2 THEN IF (temp_service_end_at > order_row.created_at) THEN temp_service_start_at := TO_CHAR(temp_service_end_at + '1 month'::INTERVAL, 'YYYY-MM-01 00:00:00'); ELSE - temp_service_start_at := TO_CHAR(order_row.created_at + (order_row.effect_months || ' month')::INTERVAL, + temp_service_start_at := TO_CHAR(order_row.created_at + (package_row->>'effect_months' || ' month')::INTERVAL, 'YYYY-MM-01 00:00:00'); END IF; temp_service_end_at := - temp_service_start_at + order_row.counts * (order_row.service_months || ' month')::INTERVAL + - (order_row.delay_months || ' month')::INTERVAL - '1 second'::INTERVAL; + temp_service_start_at + order_row.counts * (package_row->>'service_months' || ' month')::INTERVAL + + (package_row->>'delay_months' || ' month')::INTERVAL - '1 second'::INTERVAL; ELSE -- 先购买了加油包后再激活的 IF (order_row.created_at < activated_at) THEN @@ -92,15 +95,15 @@ BEGIN ELSE -- 延时生效 temp_service_start_at := - TO_CHAR(activated_at + (order_row.effect_months || ' month')::INTERVAL, 'YYYY-MM-01 00:00:00'); + TO_CHAR(activated_at + (package_row->>'effect_months' || ' month')::INTERVAL, 'YYYY-MM-01 00:00:00'); END IF; ELSE -- 延时生效 - temp_service_start_at := TO_CHAR(order_row.created_at + (order_row.effect_months || ' month')::INTERVAL, + temp_service_start_at := TO_CHAR(order_row.created_at + (package_row->>'effect_months' || ' month')::INTERVAL, 'YYYY-MM-01 00:00:00'); END IF; - temp_service_end_at := temp_service_start_at + (order_row.service_months || ' month')::INTERVAL + - (order_row.delay_months || ' month')::INTERVAL - '1 second'::INTERVAL; + temp_service_end_at := temp_service_start_at + (package_row->>'service_months' || ' month')::INTERVAL + + (package_row->>'delay_months' || ' month')::INTERVAL - '1 second'::INTERVAL; END CASE; END IF; @@ -112,7 +115,6 @@ BEGIN service_end_at := COALESCE(order_row.service_end_at::TIMESTAMP, temp_service_end_at::TIMESTAMP); RETURN NEXT; END LOOP; - RAISE NOTICE 't5'; RETURN; END; $$ LANGUAGE plpgsql; diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index 476368f7..fc757996 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -10,5 +10,3 @@ use Illuminate\Database\Schema\Blueprint; use App\Domains\Virtual\Services\OrderService; require_once realpath(dirname(__FILE__) . '/TestCase.php'); - -var_dump(preg_match('/[1-2][0-9]{3}[0-1][0-9]/', '201901')); diff --git a/tests/MongoTest.php b/tests/MongoTest.php index 88bfd86a..c0e997e4 100644 --- a/tests/MongoTest.php +++ b/tests/MongoTest.php @@ -5,7 +5,7 @@ use App\Domains\Card\Services\CardService; require_once realpath(dirname(__FILE__) . '/TestCase.php'); $simArray = [ - '1440418967511' + '1440418268370' ]; $res = CardService::getMongoCardsInfo($simArray); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 2b63a117..b33d5ef8 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -9,6 +9,7 @@ return array( 'AccountSeeder' => $baseDir . '/database/seeds/AccountSeeder.php', 'AddBusinessTypeToRealOrders' => $baseDir . '/database/migrations/2019_04_16_110601_add_business_type_to_real_orders.php', 'AddRealOrderGroupPackageCardsPartition' => $baseDir . '/database/migrations/2019_04_17_161638_add_real_order_group_package_cards_partition.php', + 'AddVirtualOrderUpgradeCardsPartition' => $baseDir . '/database/migrations/2019_04_23_102650_add_virtual_order_upgrade_cards_partition.php', 'ArithmeticError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php', 'AssertionError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php', 'CompanyAccountSeeder' => $baseDir . '/database/seeds/CompanyAccountSeeder.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 667dc7e8..fe300f68 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -728,6 +728,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9 'AccountSeeder' => __DIR__ . '/../..' . '/database/seeds/AccountSeeder.php', 'AddBusinessTypeToRealOrders' => __DIR__ . '/../..' . '/database/migrations/2019_04_16_110601_add_business_type_to_real_orders.php', 'AddRealOrderGroupPackageCardsPartition' => __DIR__ . '/../..' . '/database/migrations/2019_04_17_161638_add_real_order_group_package_cards_partition.php', + 'AddVirtualOrderUpgradeCardsPartition' => __DIR__ . '/../..' . '/database/migrations/2019_04_23_102650_add_virtual_order_upgrade_cards_partition.php', 'ArithmeticError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php', 'AssertionError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php', 'CompanyAccountSeeder' => __DIR__ . '/../..' . '/database/seeds/CompanyAccountSeeder.php',