导入模板

This commit is contained in:
邓皓元 2019-04-17 19:12:52 +08:00
parent 0cb9e3d513
commit e81521e899
13 changed files with 292 additions and 119 deletions

View File

@ -31,6 +31,7 @@ class AddedOrderSync extends Command
'real_order_flows_package_cards',
'real_order_optional_package_cards',
'real_order_additional_package_cards',
'real_order_group_package_cards',
];
public function handle()
@ -88,7 +89,14 @@ class AddedOrderSync extends Command
$virtualTable = str_replace('real_', 'virtual_', $table);
if (!in_array($virtualTable, ['virtual_order_optional_package_cards', 'virtual_order_additional_package_cards'])) {
if (in_array($virtualTable, ['virtual_order_optional_package_cards', 'virtual_order_additional_package_cards'])) {
$virtualTable = 'virtual_order_flows_package_cards';
}
if (in_array($virtualTable, ['virtual_order_group_package_cards'])) {
$virtualTable = 'virtual_order_renewal_cards';
}
$starttime = $this->datetime->copy()->startOfMonth()->startOfDay();
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
@ -107,7 +115,6 @@ class AddedOrderSync extends Command
array_push($simArray, $value['sim']);
$value['virtual_order_id'] = $orders[$value['sim']][$i]['order_id'] ?? 0;
}
}
MongoCardJob::dispatch(array_pluck($data, 'sim'));
@ -184,7 +191,7 @@ class AddedOrderSync extends Command
];
$cards = DB::connection('real')->table('jxc_custom_order_item')->select($select)
->whereIn('sn', array_keys($orders))->where('goods_type', '<', 6)->get()->collect()->toArray();
->whereIn('sn', array_keys($orders))->where('goods_type', '<=', 6)->get()->collect()->toArray();
$array = [];

View File

@ -39,7 +39,7 @@ class PackageSync extends Command
$flowPackages = $this->getFlowPackages();
$optionalPackages = $this->getOptionalPackages();
$additionalPackages = $this->getAdditionalPackages();
$groupPackages = $this->getGroupPackages();
$groupPackages = $this->getGroupPackages($basePackages);
$packages = array_merge($renewalPackages, $flowPackages, $optionalPackages, $additionalPackages, $groupPackages);
@ -206,28 +206,45 @@ class PackageSync extends Command
}
// 组合包
protected function getGroupPackages()
protected function getGroupPackages($basePackages)
{
$basePackages = array_keyBy($basePackages, 'sn');
$select = [
DB::raw('6 as type'),
'jxc_package_addoptional.bag_number as sn',
'jxc_package_addoptional.name as name',
DB::raw('"qw" as carrier_operator'),
DB::raw('0 as cost_price'),
'jxc_package_addoptional.guide_price as guide_price',
DB::raw('0 as flows'),
'jxc_package_addoptional.content_count as messages',
'jxc_package_addoptional.reset_cycle as reset_months',
'jxc_package_addoptional.service_cycle as service_months',
'jxc_package_addoptional.create_time as created_at',
'jxc_package_addoptional.del',
'jxc_package_group.sn as sn',
'jxc_package_group.name as name',
'jxc_package_group_item.package_sn as parent_sn',
'jxc_package_group.price as cost_price',
'jxc_package_group.price as guide_price',
'jxc_package_group.createtime as created_at',
'jxc_package_group.del',
];
$packages = DB::connection('real')->table('jxc_package_addoptional')->join('jxc_package_value_add_relation', function ($join) {
$join->on('jxc_package_value_add_relation.value_add_number', '=', 'jxc_package_addoptional.bag_number')
->whereIn('jxc_package_value_add_relation.custom_no', $this->companies)
->where('jxc_package_value_add_relation.type', 4);
})->select($select)->where('jxc_package_addoptional.tid', 1)->get();
$packages = DB::connection('real')->table('jxc_package_group')->join('jxc_package_group_item', function ($join) {
$join->on('jxc_package_group_item.sn', '=', 'jxc_package_group.sn')
->where('jxc_package_group_item.type', 1);
})->select($select)->get();
$packages->map(function ($item, $index) use ($basePackages, &$packages) {
$basePackage = $basePackages[$item->parent_sn];
if (!$basePackage) {
unset($packages[$index]);
return;
throw new InvalidArgumentException('组合包未找到对应基础套餐 #:'.$item->sn);
}
$item->parent_id = $basePackage['id'];
$item->carrier_operator = array_flip(self::$carrier_operator)[$basePackage['carrier_operator']] ?? 'qw';
$item->flows = $basePackage['flows'];
$item->voices = $basePackage['voices'];
$item->messages = $basePackage['messages'];
$item->has_messages = $basePackage['has_messages'];
$item->has_lbs = $basePackage['has_lbs'];
$item->reset_months = $basePackage['reset_months'];
$item->service_months = $basePackage['service_months'];
});
return $this->transform($packages);
}

View File

@ -39,6 +39,7 @@ class OrderController extends Controller
$orders->transform(function ($item) {
return $item->only([
'id',
'type',
'sn',
'business_type',
'business_type_name',

View File

@ -2,6 +2,7 @@
namespace App\Domains\Virtual\Services;
use App\Dicts;
use Carbon\Carbon;
use App\Core\Service;
use App\Models\Card\Card;
use App\Models\Virtual\Order;
@ -183,45 +184,6 @@ class OrderService extends Service
}
try {
// 改企业的卡新增一批虚拟卡,并替换原有订单里的卡
if (isset($attributes['sign']) && $attributes['sign'] == 2) {
$simArray = implode(',', array_pluck($attributes['selected'], 'sim'));
try {
DB::statement("select change_cards('{{$simArray}}'::INT8[]);");
} catch (\Throwable $th) {
throw $th;
}
}
// 转销售和改企业的都立即激活卡
if (isset($attributes['sign']) && in_array($attributes['sign'], [1, 2])) {
$array = array_map(function ($item) use ($attributes) {
return ['sim' => $item['sim'], 'virtual_activated_at' => $attributes['order_at']];
}, $attributes['selected']);
Card::upsert($array, 'sim', ['virtual_activated_at']);
$attributes['type'] = 0;
$originType = $attributes['type'];
// 销售订单,如果单卡使用多次,仅第一次为销售,其他改续费。
$extras = [];
$selected = $attributes['selected'];
$attributes['counts'] = count($selected);
foreach ($selected as &$card) {
if ($card['counts'] > 1) {
array_push($extras, [
'sim' => $card['sim'],
'counts' => $card['counts'] - 1,
]);
$card['counts'] = 1;
}
}
$attributes['selected'] = $selected;
}
if ($attributes['id']) {
if (!$node = $this->orderRepository->find($attributes['id'])) {
throw new NotExistException('订单不存在或已删除');
@ -265,13 +227,126 @@ class OrderService extends Service
]);
}
} else {
$maxId = Order::withTrashed()->max('id');
$attributes['id'] = ++$maxId;
if ($product->company_id != $attributes['company_id']) {
throw new NotAllowedException('非法操作');
}
$maxId = Order::withTrashed()->max('id');
if ($attributes['type'] !== 0) {
$simArray = array_unique(array_pluck($attributes['selected'], 'sim'));
$simCompany = $this->orderCardPartitionRepository->select(['sim', 'company_id'])
->where('type', 0)->whereIn('sim', $simArray)
->get()->pluck('company_id', 'sim')->toArray();
$news = [];
$extras = [];
foreach ($simArray as $value) {
if (!in_array($value, array_keys($simCompany))) {
array_push($news, $value);
continue;
}
if ($simCompany[$value] !== $attributes['company_id']) {
array_push($extras, $value);
continue;
}
}
if (count($news)) {
// 按订单时间激活
$array = array_map(function ($item) use ($newOrderData) {
return ['sim' => $item, 'virtual_activated_at' => $newOrderData['order_at']];
}, $news);
Card::upsert($array, 'sim', ['virtual_activated_at']);
// 创建订单
$newOrderData = array_except($attributes, ['selected', 'sign']);
$newOrderData['id'] = ++$maxId;
$newOrderData['sn'] = $this->generateSn();
$newOrderData['type'] = 0;
$newOrderData['order_status'] = 5;
$newOrderData['transaction_status'] = 1;
$newOrderData['counts'] = count($news);
$newOrderData['total_price'] = $attributes['unit_price'] * count($news);
$newOrderData['custom_price'] = $attributes['unit_price'] * count($news);
$newOrderData['order_at'] = $attributes['order_at'] ?? date('Y-m-d H:i:s');
$newOrderData['package_id'] = $attributes['package_id'] ?? $product->package_id;
$newOrder = $this->orderRepository->create($newOrderData);
// 创建订单卡关联
$this->upsertOrderCards(array_map(function ($item) {
return ['sim' => $item, 'counts' => 1];
}, $news), $newOrder);
// 剩下需要续费的卡
$selected = $attributes['selected'];
$selectedNews = [];
foreach ($selected as $key => $item) {
if (isset($selectedNews[$item['sim']])) {
$selectedNews[$item['sim']]['counts'] += $item['counts'];
continue;
}
if (in_array($item['sim'], $news)) {
$counts = $item['counts'] - 1;
$selectedNews[$item['sim']] = [
'sim' => $item['sim'],
'counts' => $counts
];
continue;
}
$selectedNews[$item['sim']] = [
'sim' => $item['sim'],
'counts' => $item['counts'],
];
}
$selectedNews = array_filter($selectedNews, function ($item) {
return $item['counts'] > 0;
});
$attributes['counts'] = array_sum(array_pluck($selectedNews, 'counts'));
$attributes['selected'] = array_values($selectedNews);
}
if (count($extras)) {
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;
$having = "MAX(service_end_at) < '%s'";
$having = sprintf($having, Carbon::now()->subMonths(6)->endOfMonth());
$replacement = $this->orderCardPartitionRepository->select(['sim'])
->where('company_id', $attributes['company_id'])
->where('package_id', $attributes['package_id'])
->whereIn('type', [0, 1])
->groupBy('sim')
->havingRaw($having)
->get()->pluck('sim')->toArray();
if (count($replacement) !== count($extras)) {
throw new NotAllowedException('可替换的卡量不足,不能进行转销售操作');
}
$updates = [];
foreach ($extras as $key => $value) {
$updates[] = [
'sim' => $value,
'original_sim' => $replacement[$key],
];
}
$this->orderCardPartitionRepository->updateBatch($updates, 'sim');
}
}
if ($attributes['counts'] !== 0) {
$attributes['id'] = ++$maxId;
if (isset($attributes['selected']) && count($attributes['selected']) === $attributes['counts']) {
$attributes['order_status'] = 5;
@ -285,16 +360,15 @@ class OrderService extends Service
$node = $this->orderRepository->create($attributes);
}
}
if ($attributes['selected']) {
if (isset($attributes['selected']) && is_array($attributes['selected']) && count($attributes['selected'])) {
if ($attributes['type'] === 0) {
$exists = $this->orderCardPartitionRepository->withConditions([
'type' => 0,
'sim' => array_pluck($attributes['selected'], 'sim')
])->count();
if ($exists) {
DB::rollBack();
$simArray = implode(',', array_pluck($attributes['selected'], 'sim'));
@ -304,24 +378,11 @@ class OrderService extends Service
try {
$this->upsertOrderCards($attributes['selected'], $node);
$this->orderRepository->forgetCached();
$this->orderCardPartitionRepository->forgetCached();
app(RealOrderCardPartitionRepository::class)->forgetCached();
} catch (\Exception $e) {
DB::rollBack();
throw $e;
}
}
if (!empty($extras)) {
$extraOrderData = $attributes;
$extraOrderData['type'] = $originType;
$extraOrderData['counts'] = array_sum(array_pluck($extras, 'counts'));
$extraOrderData['total_price'] = $attributes['unit_price'] * $extraOrderData['counts'];
$extraOrderData['custom_price'] = $attributes['unit_price'] * $extraOrderData['counts'];
$extraOrder = $this->orderRepository->create($attributes);
$this->upsertOrderCards($extras, $extraOrder);
}
} catch (\Exception $e) {
DB::rollBack();
throw $e;
@ -329,6 +390,10 @@ class OrderService extends Service
DB::commit();
$this->orderRepository->forgetCached();
$this->orderCardPartitionRepository->forgetCached();
app(RealOrderCardPartitionRepository::class)->forgetCached();
return $node;
}
@ -585,7 +650,7 @@ class OrderService extends Service
if ($node->type === 0) {
$sql = 'SELECT COUNT(*) as counts FROM virtual_order_cards_partition WHERE type != 0 AND sim In (
SELECT sim FROM virtual_order_cards_partition WHERE order_id = ?
)';
) AND deleted_at IS NULL';
$counts = DB::select($sql, [$id])[0]->counts;

View File

@ -40,7 +40,6 @@ class CreateRealOrderCardsTable extends Migration
$table->addPartition('real_order_flows_package_cards', 'list', [3]);
$table->addPartition('real_order_optional_package_cards', 'list', [4]);
$table->addPartition('real_order_additional_package_cards', 'list', [5]);
$table->addPartition('real_order_group_package_cards', 'list', [6]);
});
Schema::table('real_order_cards', function (Blueprint $table) {
@ -63,14 +62,6 @@ class CreateRealOrderCardsTable extends Migration
Schema::table('real_order_optional_package_cards', function (Blueprint $table) {
$table->unique(['sim', 'order_id', 'deleted_at']);
});
Schema::table('real_order_additional_package_cards', function (Blueprint $table) {
$table->unique(['sim', 'order_id', 'deleted_at']);
});
Schema::table('real_order_group_package_cards', function (Blueprint $table) {
$table->unique(['sim', 'order_id', 'deleted_at']);
});
}
/**

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddRealOrderGroupPackageCardsPartition extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('real_order_cards_partition', function (Blueprint $table) {
$table->addPartition('real_order_group_package_cards', 'list', [6]);
});
Schema::table('real_order_group_package_cards', function (Blueprint $table) {
$table->unique(['sim', 'order_id', 'deleted_at']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('real_order_group_package_cards');
}
}

View File

@ -721,7 +721,7 @@ export default {
this.cloneColumns.forEach(col => (col._filterVisible = false));
},
handleBodyScroll(event) {
if (this.showHeader)
if (this.showHeader && this.$refs.header)
this.$refs.header.scrollLeft = event.target.scrollLeft;
if (this.isLeftFixed)
this.$refs.fixedBody.scrollTop = event.target.scrollTop;

View File

@ -67,6 +67,18 @@
</Select>
</li>
<li class="handle-item w-200" v-if="[1, 3].indexOf(type) !== -1">
<Select clearable placeholder="订单类型" v-model="params.order_type">
<Option :value="0" v-if="type === 0">销售</Option>
<Option :value="1" v-if="type === 1">续费</Option>
<Option :value="2" v-if="type === 2">续费包</Option>
<Option :value="3" v-if="type === 3">加油包</Option>
<Option :value="4" v-if="type === 3">可选包</Option>
<Option :value="5" v-if="type === 3">附加包</Option>
<Option :value="6" v-if="type === 1">组合包</Option>
</Select>
</li>
<li class="handle-item w-200">
<Select clearable placeholder="支付方式" v-model="params.pay_channel_name">
<Option :value="'银行转账'">银行转账</Option>

View File

@ -64,8 +64,18 @@ export default {
limit: 10,
page: 1
},
orderTypes: [
"销售",
"续费",
"续费包",
"加油包",
"可选包",
"附加包",
"组合包"
],
params: {
sn: "",
order_type: "",
company_name: "",
package_name: "",
carrier_operator: "",
@ -224,6 +234,14 @@ export default {
width: 80,
sortable: true
},
{
title: "订单类型",
key: "",
width: 90,
render: (h, context) => {
return h("span", this.orderTypes[context.row.type]);
}
},
{
title: "企业名称",
key: "company_name",
@ -475,6 +493,7 @@ export default {
if (this.params.sim !== "") {
params.sim = this.params.sim;
let cardParams = { type: this.type, sim: this.params.sim };
cardParams = this.transformerParams(cardParams);
this.params.time = [];
this.cardLoading = true;
this.$store
@ -488,6 +507,8 @@ export default {
});
}
params = this.transformerParams(params);
this.$store
.dispatch("getOrders", params)
.then(() => {
@ -580,6 +601,15 @@ export default {
});
}
if (
this.params.order_type !== "" &&
this.params.order_type !== undefined
) {
filterOrders = filterOrders.filter(el => {
return el.type === this.params.order_type;
});
}
if (
this.params.carrier_operator !== "" &&
this.params.carrier_operator !== undefined
@ -663,6 +693,7 @@ export default {
exportOrders() {
let columns = [
{ title: "订单编号", key: "sn" },
{ title: "订单类型", key: "order_type" },
{ title: "企业名称", key: "company_name" },
{ title: "运营商", key: "carrier_operator_name" },
{ title: "套餐名称", key: "package_name" },
@ -702,6 +733,7 @@ export default {
let obj = {
sn: order.sn + "\t",
order_type: this.orderTypes[order.type],
company_name: order.company_name,
carrier_operator_name: order.carrier_operator_name,
package_name: order.package_name,
@ -766,6 +798,7 @@ export default {
this.cardLoading = true;
return new Promise(resolve => {
let params = { order_id: order_id, type: this.type };
params = this.transformerParams(params);
this.$store
.dispatch("getCards", params)
.then(cards => {
@ -788,7 +821,6 @@ export default {
this.getCards(order_id).then(cards => {
cards = this.getFilterUsedCards(cards);
cards = this.getFilterDiffComPacCards(cards);
console.log(cards);
if (!cards.length) {
return this.$Message.error("所有卡都不可使用");
@ -1006,6 +1038,15 @@ export default {
},
getFilterDiffComPacCards(cards) {
return cards.filter(item => !this.isDiffCompany(item));
},
transformerParams(params) {
if (params.type === 1) {
params.type = [1, 6];
} else if (params.type === 3) {
params.type = [3, 5, 6];
}
return params;
}
}
};

View File

@ -517,6 +517,7 @@ export default {
});
},
handelSuccess() {
this.$Message.info("操作成功");
if (Object.keys(this.order_group).length >= 1) {
let mapped = JSON.parse(JSON.stringify(this.order_group));
this.$store.dispatch("removeSelected", mapped[this.groupIndex]);
@ -524,10 +525,11 @@ export default {
this.$store.commit("SET_ORDER_GROUP", mapped);
let nextIndex = Object.keys(this.order_group)[0];
if (nextIndex !== undefined) {
this.selectGroup(this.order_group[nextIndex], nextIndex);
}
this.$Message.info("操作成功");
}
if (!this.order_group || Object.keys(this.order_group).length < 1) {
this.clear();

View File

@ -1045,6 +1045,7 @@ export default {
handleOrderSuccess(value) {
let page = value ? this.list_data.current_page : 1;
this.cardsObj.show = false;
this.editObj.show = false;
this.shipObj.show = false;
this.orderConfirmShow = false;
this.$store.dispatch("initOrder");

View File

@ -8,6 +8,7 @@ $baseDir = dirname($vendorDir);
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',
'ArithmeticError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php',
'AssertionError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php',
'CompanyAccountSeeder' => $baseDir . '/database/seeds/CompanyAccountSeeder.php',

View File

@ -727,6 +727,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
public static $classMap = array (
'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',
'ArithmeticError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php',
'AssertionError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php',
'CompanyAccountSeeder' => __DIR__ . '/../..' . '/database/seeds/CompanyAccountSeeder.php',