RD同步修改
This commit is contained in:
parent
cf4d708d57
commit
ea762c02fa
@ -14,5 +14,4 @@ class CardService extends Service
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Domains\Real\Commands\Sync;
|
||||
|
||||
use App\Models\Real\AddedOrder;
|
||||
use App\Models\Real\Order;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Domains\Real\Services\CommonService;
|
||||
use App\Domains\Real\Repositories\OrderRepository;
|
||||
use App\Domains\Real\Repositories\CompanyRepository;
|
||||
use App\Domains\Real\Repositories\PackageRepository;
|
||||
use App\Domains\Real\Repositories\AddedOrderRepository;
|
||||
use App\Domains\Real\Repositories\OrderCardPartitionRepository;
|
||||
|
||||
class AddedOrderSync extends Command
|
||||
{
|
||||
@ -19,6 +21,15 @@ class AddedOrderSync extends Command
|
||||
|
||||
protected $types;
|
||||
|
||||
protected $tables = [
|
||||
'',
|
||||
'real_order_renewal_cards',
|
||||
'real_order_renewal_package_cards',
|
||||
'real_order_flows_package_cards',
|
||||
'real_order_optional_package_cards',
|
||||
'real_order_additional_package_cards',
|
||||
];
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->datetime = $this->getDateTime();
|
||||
@ -26,49 +37,53 @@ class AddedOrderSync extends Command
|
||||
$this->packages = app(PackageRepository::class)->withTrashed()->get()->keyBy('sn');
|
||||
|
||||
$orders = $this->getOrders();
|
||||
$orderItems = $this->getOrderItems($orders);
|
||||
|
||||
foreach ($orders as &$item) {
|
||||
$item['type'] = $this->types[$item['sn']] ?? 255;
|
||||
}
|
||||
|
||||
$dataOrderCards = [];
|
||||
|
||||
foreach ($orderItems as $key => $value) {
|
||||
$dataOrderCards[$value['type']][] = [
|
||||
'type' => $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'],
|
||||
];
|
||||
}
|
||||
$cards = $this->getOrderItems($orders);
|
||||
$orders = $this->transformer($orders, $cards);
|
||||
|
||||
$this->line('插入订单数据,条数:'.count($orders));
|
||||
foreach (array_chunk($orders, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
AddedOrder::upsert($orders, 'id');
|
||||
Order::upsert($orders, ['sn', 'deleted_at']);
|
||||
}
|
||||
|
||||
$orders = Order::whereIn('sn', array_pluck($orders, 'sn'))->get()->keyBy('sn');
|
||||
|
||||
app(OrderRepository::class)->forgetCached();
|
||||
|
||||
$dataOrderCards = [];
|
||||
|
||||
foreach ($cards as $value) {
|
||||
$sn = $value['sn'] . $value['package_id'];
|
||||
|
||||
if (!$order = $orders[$sn]) {
|
||||
Log::notice("卡 {$value['sim']} 订单未找到");
|
||||
}
|
||||
|
||||
$dataOrderCards[$value['type']][] = [
|
||||
'type' => $value['type'],
|
||||
'sim' => $value['sim'],
|
||||
'company_id' => $value['company_id'],
|
||||
'order_id' => $order['id'],
|
||||
'package_id' => $value['package_id'],
|
||||
'counts' => $value['counts'],
|
||||
'unit_price' => $value['unit_price'],
|
||||
'created_at' => $value['created_at'],
|
||||
'updated_at' => $value['updated_at'],
|
||||
'deleted_at' => $value['deleted_at'],
|
||||
];
|
||||
}
|
||||
app(AddedOrderRepository::class)->forgetCached();
|
||||
|
||||
$this->line('插入订单关联数据,条数:'.count(array_collapse($dataOrderCards)));
|
||||
$tables = [
|
||||
'',
|
||||
'real_added_order_renewal_cards',
|
||||
'real_added_order_renewal_package_cards',
|
||||
'real_added_order_flows_package_cards',
|
||||
'real_added_order_optional_package_cards',
|
||||
'real_added_order_additional_package_cards',
|
||||
];
|
||||
|
||||
foreach ($dataOrderCards as $type => $orderCards) {
|
||||
foreach (array_chunk($orderCards, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
DB::table($tables[$type])->upsert($data, ['sim', 'order_id']);
|
||||
DB::table($this->tables[$type])->upsert($data, ['sim', 'order_id']);
|
||||
}
|
||||
}
|
||||
unset($dataOrderCards);
|
||||
|
||||
app(OrderCardPartitionRepository::class)->forgetCached();
|
||||
|
||||
$this->line('插入订单关联数据成功');
|
||||
}
|
||||
|
||||
@ -81,35 +96,35 @@ class AddedOrderSync extends Command
|
||||
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
|
||||
|
||||
$select = [
|
||||
'r_id as id',
|
||||
'sn as sn',
|
||||
'sn',
|
||||
'status',
|
||||
'custom_no as company_id',
|
||||
'transaction_no',
|
||||
'sim_count as counts',
|
||||
'amount_money as total_price',
|
||||
'paytype as pay_channel',
|
||||
'create_time as order_at',
|
||||
'update_time as updated_at',
|
||||
];
|
||||
|
||||
$orders = DB::connection('real')->table('jxc_custom_order')->select($select)->where('status', 3)
|
||||
$orders = DB::connection('real')->table('jxc_custom_order')->select($select)->whereIn('status', [3, 7, 8])
|
||||
->whereIn('custom_no', $this->companies->keys())
|
||||
->where('create_time', '>=', $starttime->timestamp)
|
||||
->where('create_time', '<=', $endtime->timestamp)
|
||||
->orderBy('create_time')->get()->collect()->toArray();
|
||||
|
||||
foreach ($orders as &$item) {
|
||||
$array = [];
|
||||
|
||||
foreach ($orders as $item) {
|
||||
$item['company_id'] = $this->companies[$item['company_id']]['id'] ?? 0;
|
||||
$item['total_price'] = intval($item['total_price'] * 100) ;
|
||||
$item['counts'] = !empty($item['counts']) ? $item['counts'] : 1;
|
||||
$item['pay_channel'] = CommonService::transformerPayChannel($item['pay_channel']);
|
||||
$item['unit_price'] = intval($item['total_price']/$item['counts']);
|
||||
$item['order_at'] = date('Y-m-d H:i:s', $item['order_at']);
|
||||
$item['created_at'] = $item['order_at'];
|
||||
$item['updated_at'] = ($item['updated_at'] == '0000-00-00 00:00:00') ? $item['order_at'] : $item['updated_at'];
|
||||
$item['deleted_at'] = $item['status'] === 3 ? null : $item['updated_at'];
|
||||
unset($item['status']);
|
||||
$array[] = $item;
|
||||
}
|
||||
|
||||
return $orders;
|
||||
return $array;
|
||||
}
|
||||
|
||||
// 订单详情
|
||||
@ -120,26 +135,80 @@ class AddedOrderSync extends Command
|
||||
$this->line('查询订单详情');
|
||||
|
||||
$select = [
|
||||
'sn as order_sn',
|
||||
'sn',
|
||||
'sim',
|
||||
'goods_no as package_id',
|
||||
'goods_type as type',
|
||||
'goods_no as package_sn',
|
||||
'unit_price as unit_price',
|
||||
'quantity as counts',
|
||||
];
|
||||
|
||||
$orderItems = DB::connection('real')->table('jxc_custom_order_item')->select($select)
|
||||
$cards = DB::connection('real')->table('jxc_custom_order_item')->select($select)
|
||||
->whereIn('sn', array_keys($orders))->where('goods_type', '<', 6)->get()->collect()->toArray();
|
||||
|
||||
foreach ($orderItems as &$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;
|
||||
$array = [];
|
||||
|
||||
foreach ($cards as $item) {
|
||||
$order = $orders[$item['sn']];
|
||||
$item['company_id'] = $order['company_id'] ?? 0;
|
||||
$item['package_id'] = $this->packages[$item['package_sn']]['id'] ?? 0;
|
||||
$item['unit_price'] = intval($item['unit_price'] * 100) ;
|
||||
$item['created_at'] = $order['created_at'];
|
||||
$item['updated_at'] = $order['updated_at'];
|
||||
$item['deleted_at'] = $order['deleted_at'];
|
||||
$array[] = $item;
|
||||
}
|
||||
|
||||
$this->types = array_pluck($orderItems, 'type', 'order_sn');
|
||||
$this->types = array_pluck($array, 'type', 'sn');
|
||||
|
||||
return $orderItems;
|
||||
return $array;
|
||||
}
|
||||
|
||||
// 整理数据
|
||||
protected function transformer($orders, $cards)
|
||||
{
|
||||
$orderArray = [];
|
||||
$orderPackages = [];
|
||||
|
||||
$tmpCards = $cards;
|
||||
$tmpCards = array_groupBy($tmpCards, 'sn');
|
||||
|
||||
foreach ($tmpCards as $sn => $item) {
|
||||
$array = array_groupBy($item, 'package_id');
|
||||
foreach ($array as $package_id => $values) {
|
||||
if (empty($values)) {
|
||||
Log::notice("订单 {$sn} 数据为空");
|
||||
continue;
|
||||
}
|
||||
|
||||
$orderPackages[$sn][$package_id] = [
|
||||
'unit_price' => $values[0]['unit_price'],
|
||||
'counts' => array_sum(array_pluck($values, 'counts')),
|
||||
'total_price' => $values[0]['unit_price'] * array_sum(array_pluck($values, 'counts')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($orders as $item) {
|
||||
$item['type'] = $this->types[$item['sn']] ?? 255;
|
||||
$packages = $orderPackages[$item['sn']];
|
||||
|
||||
if (!$packages) {
|
||||
Log::notice("订单 {$sn} 关联套餐不正确");
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($packages as $package_id => $array) {
|
||||
$order = $item;
|
||||
$order['package_id'] = $package_id;
|
||||
$order['sn'] = $item['sn'] . $package_id;
|
||||
$order['counts'] = $array['counts'];
|
||||
$order['unit_price'] = $array['unit_price'];
|
||||
$order['total_price'] = $array['total_price'];
|
||||
$orderArray[] = $order;
|
||||
}
|
||||
}
|
||||
|
||||
return $orderArray;
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ namespace App\Domains\Real\Commands\Sync;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Real\Order;
|
||||
use App\Models\Real\OrderCard;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Real\OrderCardPartition;
|
||||
use App\Domains\Real\Repositories\OrderRepository;
|
||||
use App\Domains\Real\Repositories\CompanyRepository;
|
||||
use App\Domains\Real\Repositories\PackageRepository;
|
||||
use App\Domains\Real\Repositories\OrderCardRepository;
|
||||
use App\Domains\Real\Repositories\OrderCardPartitionRepository;
|
||||
|
||||
class OrderBaseSync extends Command
|
||||
{
|
||||
@ -34,24 +34,23 @@ class OrderBaseSync extends Command
|
||||
$cards = $this->getCards($orders);
|
||||
|
||||
try {
|
||||
$this->line('插入订单数据,条数:'.count($orders));
|
||||
foreach (array_chunk($orders, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
foreach ($data as &$item) {
|
||||
unset($item['package_id']);
|
||||
DB::transaction(function () use ($orders, $cards) {
|
||||
$this->line('插入订单数据,条数:'.count($orders));
|
||||
foreach (array_chunk($orders, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
Order::upsert($data, 'id');
|
||||
}
|
||||
Order::upsert($data, 'id');
|
||||
}
|
||||
app(OrderRepository::class)->forgetCached();
|
||||
$this->line('插入订单数据成功');
|
||||
app(OrderRepository::class)->forgetCached();
|
||||
$this->line('插入订单数据成功');
|
||||
|
||||
$this->line('插入订单关联数据,条数:'.count($cards));
|
||||
foreach (array_chunk($cards, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
OrderCard::upsert($data, ['sim', 'deleted_at']);
|
||||
}
|
||||
app(OrderCardRepository::class)->forgetCached();
|
||||
$this->line('插入订单关联数据成功');
|
||||
$this->line('插入订单关联数据,条数:'.count($cards));
|
||||
foreach (array_chunk($cards, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
DB::table('real_order_cards')->upsert($data, ['sim', 'deleted_at']);
|
||||
}
|
||||
app(OrderCardPartitionRepository::class)->forgetCached();
|
||||
$this->line('插入订单关联数据成功');
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
throw $e;
|
||||
@ -142,14 +141,15 @@ class OrderBaseSync extends Command
|
||||
$sim = explode('-', $value['section_no'])[0];
|
||||
$order = $orders[$item['o_number']];
|
||||
|
||||
$orderRow = $orderRows[$item['s_number']];
|
||||
|
||||
for ($i=0; $i < $value['counts']; $i++) {
|
||||
$cards[] = [
|
||||
'type' => 0,
|
||||
'sim' => intval($sim),
|
||||
'order_id' => $order['id'],
|
||||
'company_id' => $order['company_id'],
|
||||
'package_id' => $order['package_id'],
|
||||
'counts' => 1,
|
||||
'unit_price' => $order['unit_price'],
|
||||
'created_at' => $order['created_at'],
|
||||
'updated_at' => $order['updated_at'],
|
||||
'deleted_at' => $order['deleted_at'],
|
||||
|
@ -30,15 +30,19 @@ class PackageSync extends Command
|
||||
|
||||
$basePackages = $this->getBasePackages();
|
||||
|
||||
Package::upsert($basePackages, ['sn', 'deleted_at']);
|
||||
|
||||
$basePackages = Package::where('type', 0)->get()->toArray();
|
||||
|
||||
$renewalPackages = $this->getRenewalPackages($basePackages);
|
||||
|
||||
$flowPackages = $this->getFlowPackages();
|
||||
$optionalPackages = $this->getOptionalPackages();
|
||||
$additionalPackages = $this->getAdditionalPackages();
|
||||
|
||||
$packages = array_merge($basePackages, $renewalPackages, $flowPackages, $optionalPackages, $additionalPackages);
|
||||
$packages = array_merge($renewalPackages, $flowPackages, $optionalPackages, $additionalPackages);
|
||||
|
||||
Package::upsert($packages, 'id');
|
||||
Package::upsert($packages, ['sn', 'deleted_at']);
|
||||
|
||||
app(PackageRepository::class)->forgetCached();
|
||||
}
|
||||
@ -48,7 +52,6 @@ class PackageSync extends Command
|
||||
{
|
||||
$select = [
|
||||
DB::raw('0 as type'),
|
||||
'jxc_package.id as id',
|
||||
'jxc_package.package_sn as sn',
|
||||
'jxc_package.name as name',
|
||||
'jxc_package.carrieroperator as carrier_operator',
|
||||
@ -80,7 +83,6 @@ class PackageSync extends Command
|
||||
|
||||
$select = [
|
||||
DB::raw('1 as type'),
|
||||
'jxc_package_renewal.id as id',
|
||||
'jxc_package_renewal.bag_number as sn',
|
||||
'jxc_package_renewal.package_sn as parent_sn',
|
||||
'jxc_package_renewal.name as name',
|
||||
@ -122,7 +124,6 @@ class PackageSync extends Command
|
||||
{
|
||||
$select = [
|
||||
DB::raw('2 as type'),
|
||||
'jxc_package_flows.id as id',
|
||||
'jxc_package_flows.bag_number as sn',
|
||||
'jxc_package_flows.name as name',
|
||||
'jxc_package_flows.carrieroperator as carrier_operator',
|
||||
@ -152,7 +153,6 @@ class PackageSync extends Command
|
||||
{
|
||||
$select = [
|
||||
DB::raw('3 as type'),
|
||||
'jxc_package_optional.id as id',
|
||||
'jxc_package_optional.bag_number as sn',
|
||||
'jxc_package_optional.name as name',
|
||||
'jxc_package_optional.carrieroperator as carrier_operator',
|
||||
@ -182,7 +182,6 @@ class PackageSync extends Command
|
||||
{
|
||||
$select = [
|
||||
DB::raw('4 as type'),
|
||||
'jxc_package_addoptional.id as id',
|
||||
'jxc_package_addoptional.bag_number as sn',
|
||||
'jxc_package_addoptional.name as name',
|
||||
DB::raw('"qw" as carrier_operator'),
|
||||
@ -211,7 +210,6 @@ class PackageSync extends Command
|
||||
|
||||
foreach ($packages as &$package) {
|
||||
$package = (array)$package;
|
||||
$package['id'] = ($package['type'] + 1) * 1000000 + $package['id'];
|
||||
$package['parent_id'] = $package['parent_id'] ?? 0;
|
||||
$package['carrier_operator'] = self::$carrier_operator[$package['carrier_operator']] ?? 255;
|
||||
$package['cost_price'] = intval(floatval($package['cost_price']) * 100);
|
||||
@ -232,6 +230,6 @@ class PackageSync extends Command
|
||||
ksort($package);
|
||||
}
|
||||
|
||||
return array_keyBy($packages, 'id');
|
||||
return array_values(array_keyBy($packages, 'sn'));
|
||||
}
|
||||
}
|
||||
|
59
app/Domains/Real/Http/Controllers/OrderController.php
Normal file
59
app/Domains/Real/Http/Controllers/OrderController.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace App\Domains\Real\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
83
app/Domains/Real/Repositories/Concerns/OrderCardConcern.php
Normal file
83
app/Domains/Real/Repositories/Concerns/OrderCardConcern.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Real\Repositories\Concerns;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
trait OrderCardConcern
|
||||
{
|
||||
/**
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withConditions(array $conditions = [])
|
||||
{
|
||||
$this->model = $this->model->where(function ($query) use ($conditions) {
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$query->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
if (isset($conditions['type'])) {
|
||||
$conditions['type'] = array_wrap($conditions['type']);
|
||||
$query->whereIn('type', $conditions['type']);
|
||||
}
|
||||
|
||||
if (isset($conditions['order_id'])) {
|
||||
$conditions['order_id'] = array_wrap($conditions['order_id']);
|
||||
$query->whereIn('order_id', $conditions['order_id']);
|
||||
}
|
||||
|
||||
if (isset($conditions['sim'])) {
|
||||
$conditions['sim'] = array_wrap($conditions['sim']);
|
||||
$query->whereIn('sim', $conditions['sim']);
|
||||
}
|
||||
|
||||
if (isset($conditions['company_id'])) {
|
||||
$conditions['company_id'] = array_wrap($conditions['company_id']);
|
||||
$query->whereIn('company_id', $conditions['company_id']);
|
||||
}
|
||||
|
||||
if (isset($conditions['package_id'])) {
|
||||
$query->where('package_id', $conditions['package_id']);
|
||||
}
|
||||
|
||||
if (isset($conditions['carrier_operator'])) {
|
||||
$query->whereHas('package', function ($relation) use ($conditions) {
|
||||
$relation->withTrashed()->where('carrier_operator', $conditions['carrier_operator']);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($conditions['pay_channel'])) {
|
||||
$query->where('pay_channel', $conditions['pay_channel']);
|
||||
}
|
||||
|
||||
if (isset($conditions['unit_price'])) {
|
||||
$query->where('unit_price', $conditions['unit_price']);
|
||||
}
|
||||
|
||||
if (!empty($conditions['company_name'])) {
|
||||
$query->whereHas('company', function ($relation) use ($conditions) {
|
||||
$relation->withTrashed()->where('name', $conditions['company_name']);
|
||||
});
|
||||
}
|
||||
|
||||
if (!empty($conditions['package_name'])) {
|
||||
$query->whereHas('package', function ($relation) use ($conditions) {
|
||||
$relation->withTrashed()->where('name', $conditions['package_name']);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($conditions['starttime'])) {
|
||||
$query->where('created_at', '>=', Carbon::parse($conditions['starttime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['endtime'])) {
|
||||
$query->where('created_at', '<=', Carbon::parse($conditions['endtime']));
|
||||
}
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -3,10 +3,13 @@
|
||||
namespace App\Domains\Real\Repositories;
|
||||
|
||||
use App\Core\Repository;
|
||||
use App\Models\Real\AddedOrder as Model;
|
||||
use App\Models\Real\OrderCardPartition as Model;
|
||||
use App\Domains\Real\Repositories\Concerns\OrderCardConcern;
|
||||
|
||||
class AddedOrderRepository extends Repository
|
||||
class OrderCardPartitionRepository extends Repository
|
||||
{
|
||||
use OrderCardConcern;
|
||||
|
||||
/**
|
||||
* 是否关闭缓存
|
||||
*
|
||||
@ -16,7 +19,7 @@ class AddedOrderRepository extends Repository
|
||||
|
||||
/**
|
||||
* 是否开启数据转化
|
||||
*
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needTransform = false;
|
||||
@ -29,7 +32,8 @@ class AddedOrderRepository extends Repository
|
||||
'created_at' => 'like',
|
||||
];
|
||||
|
||||
public function model() {
|
||||
public function model()
|
||||
{
|
||||
return Model::class;
|
||||
}
|
||||
|
||||
@ -44,19 +48,4 @@ class AddedOrderRepository extends Repository
|
||||
{
|
||||
return $model->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withConditions(array $conditions = [])
|
||||
{
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Real\Repositories;
|
||||
|
||||
use App\Core\Repository;
|
||||
use App\Models\Real\OrderCard as Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderCardRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* 是否关闭缓存
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $cacheSkip = false;
|
||||
|
||||
/**
|
||||
* 是否开启数据转化
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needTransform = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldSearchable = [
|
||||
'id' => '=',
|
||||
'created_at' => 'like',
|
||||
];
|
||||
|
||||
public function model()
|
||||
{
|
||||
return Model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据格式化
|
||||
*
|
||||
* @param mixed $result
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transform($model)
|
||||
{
|
||||
return $model->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withConditions(array $conditions = [])
|
||||
{
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量更新激活时间
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateActivateAt(array $data)
|
||||
{
|
||||
$connection = $this->model->getConnection();
|
||||
|
||||
$arr = array_map(function ($value) {
|
||||
return sprintf("(%d, '%s'::timestamp)", $value['sim'], $value['activated_at']);
|
||||
}, $data);
|
||||
|
||||
$sql = 'UPDATE real_cards SET activated_at = list.activated_at FROM (VALUES ' . implode(',', $arr) . ') AS list(sim, activated_at) WHERE real_cards.sim = list.sim AND real_cards.activated_at IS NULL';
|
||||
|
||||
return $connection->update($sql);
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ class OrderRepository extends Repository
|
||||
|
||||
/**
|
||||
* 是否开启数据转化
|
||||
*
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needTransform = false;
|
||||
@ -29,7 +29,8 @@ class OrderRepository extends Repository
|
||||
'created_at' => 'like',
|
||||
];
|
||||
|
||||
public function model() {
|
||||
public function model()
|
||||
{
|
||||
return Model::class;
|
||||
}
|
||||
|
||||
@ -46,17 +47,67 @@ class OrderRepository extends Repository
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withConditions(array $conditions = [])
|
||||
{
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||
}
|
||||
$this->model = $this->model->where(function ($query) use ($conditions) {
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$query->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
if (isset($conditions['type'])) {
|
||||
$conditions['type'] = array_wrap($conditions['type']);
|
||||
$query->whereIn('type', $conditions['type']);
|
||||
}
|
||||
|
||||
if (isset($conditions['company_id'])) {
|
||||
$conditions['company_id'] = array_wrap($conditions['company_id']);
|
||||
$query->whereIn('company_id', $conditions['company_id']);
|
||||
}
|
||||
|
||||
if (!empty($conditions['sn'])) {
|
||||
$query->where('sn', "%{$conditions['sn']}%");
|
||||
}
|
||||
|
||||
if (isset($conditions['transaction_no'])) {
|
||||
$query->where('transaction_no', $conditions['transaction_no']);
|
||||
}
|
||||
|
||||
if (isset($conditions['carrier_operator'])) {
|
||||
$query->whereHas('package', function ($relation) use ($conditions) {
|
||||
$relation->withTrashed()->where('carrier_operator', $conditions['carrier_operator']);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($conditions['pay_channel'])) {
|
||||
$query->where('pay_channel', $conditions['pay_channel']);
|
||||
}
|
||||
|
||||
if (!empty($conditions['company_name'])) {
|
||||
$query->whereHas('company', function ($relation) use ($conditions) {
|
||||
$relation->withTrashed()->where('name', $conditions['company_name']);
|
||||
});
|
||||
}
|
||||
|
||||
if (!empty($conditions['package_name'])) {
|
||||
$query->whereHas('package', function ($relation) use ($conditions) {
|
||||
$relation->withTrashed()->where('name', $conditions['package_name']);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($conditions['starttime'])) {
|
||||
$query->where('order_at', '>=', Carbon::parse($conditions['starttime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['endtime'])) {
|
||||
$query->where('order_at', '<=', Carbon::parse($conditions['endtime']));
|
||||
}
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
app/Domains/Real/Services/OrderService.php
Normal file
35
app/Domains/Real/Services/OrderService.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace App\Domains\Real\Services;
|
||||
|
||||
use App\Core\Service;
|
||||
use App\Domains\Real\Repositories\OrderRepository;
|
||||
use App\Domains\Real\Repositories\AddedOrderRepository;
|
||||
|
||||
class OrderService extends Service
|
||||
{
|
||||
public $orderRepository;
|
||||
public $addedOrderRepository;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(OrderRepository $orderRepository, AddedOrderRepository $addedOrderRepository)
|
||||
{
|
||||
$this->orderRepository = $orderRepository;
|
||||
$this->addedOrderRepository = $addedOrderRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
$conditions['type'] = $conditions['type'] ?? 0;
|
||||
|
||||
$repository = !$conditions['type'] ? $this->orderRepository : $this->addedOrderRepository;
|
||||
}
|
||||
}
|
13
app/Domains/Real/Tests/Services/OrderServiceTest.php
Normal file
13
app/Domains/Real/Tests/Services/OrderServiceTest.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Domains\Real\Tests\Services;
|
||||
|
||||
use App\Core\TestCase;
|
||||
use App\Domains\Real\Services\OrderService;
|
||||
|
||||
class OrderServiceTest extends TestCase
|
||||
{
|
||||
public function testOrderServiceTest()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
@ -5,18 +5,12 @@ use App\Core\Service;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Domains\Virtual\Repositories\OrderRepository;
|
||||
use App\Domains\Virtual\Repositories\CompanyRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderRenewalCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderRenewalPackageCardRepository;
|
||||
|
||||
class CompanyCountService extends Service
|
||||
{
|
||||
protected $companyRepository;
|
||||
protected $orderRepository;
|
||||
protected $orderCardRepository;
|
||||
protected $orderRenewalCardRepository;
|
||||
protected $orderRenewalPackageCardRepository;
|
||||
protected $orderCardPartitionRepository;
|
||||
|
||||
/**
|
||||
@ -27,16 +21,10 @@ class CompanyCountService extends Service
|
||||
public function __construct(
|
||||
CompanyRepository $companyRepository,
|
||||
OrderRepository $orderRepository,
|
||||
OrderCardRepository $orderCardRepository,
|
||||
OrderRenewalCardRepository $orderRenewalCardRepository,
|
||||
OrderRenewalPackageCardRepository $orderRenewalPackageCardRepository,
|
||||
OrderCardPartitionRepository $orderCardPartitionRepository
|
||||
) {
|
||||
$this->companyRepository = $companyRepository;
|
||||
$this->orderRepository = $orderRepository;
|
||||
$this->orderCardRepository = $orderCardRepository;
|
||||
$this->orderRenewalCardRepository = $orderRenewalCardRepository;
|
||||
$this->orderRenewalPackageCardRepository = $orderRenewalPackageCardRepository;
|
||||
$this->orderCardPartitionRepository = $orderCardPartitionRepository;
|
||||
}
|
||||
|
||||
@ -59,17 +47,17 @@ class CompanyCountService extends Service
|
||||
|
||||
$select = [$groupBy, DB::raw('count(distinct sim) as counts')];
|
||||
|
||||
$total = $this->orderCardRepository->select($select)->groupBy($groupBy)->get()->pluck('counts', 'company_id')->toArray();
|
||||
$total = $this->orderCardPartitionRepository->select($select)->where('type', 0)->groupBy($groupBy)->get()->pluck('counts', 'company_id')->toArray();
|
||||
|
||||
$conditions = array_only($conditions, ['starttime', 'endtime']);
|
||||
|
||||
$counts = $this->orderCardRepository->select($select)->withConditions($conditions)->groupBy($groupBy)
|
||||
$counts = $this->orderCardPartitionRepository->select($select)->where('type', 0)->withConditions($conditions)->groupBy($groupBy)
|
||||
->get()->pluck('counts', 'company_id')->toArray();
|
||||
|
||||
$orderRenewalCard = $this->orderRenewalCardRepository->select($select)->withConditions($conditions)->groupBy($groupBy)
|
||||
$orderRenewalCard = $this->orderCardPartitionRepository->select($select)->where('type', 1)->withConditions($conditions)->groupBy($groupBy)
|
||||
->get()->pluck('counts', 'company_id')->toArray();
|
||||
|
||||
// $orderRenewalPackage = $this->orderRenewalPackageCardRepository->select($select)->withConditions($conditions)->groupBy($groupBy)
|
||||
// $orderRenewalPackage = $this->orderCardPartitionRepository->select($select)->where('type', 2)->withConditions($conditions)->groupBy($groupBy)
|
||||
// ->get()->pluck('counts', 'company_id')->toArray();
|
||||
|
||||
// $renewed_counts = array_merge_sum($orderRenewalCard, $orderRenewalPackage);
|
||||
|
@ -8,19 +8,14 @@ use App\Domains\Virtual\Services\CommonService;
|
||||
use App\Domains\Virtual\Repositories\OrderRepository;
|
||||
use App\Domains\Virtual\Repositories\CompanyRepository;
|
||||
use App\Domains\Virtual\Repositories\PackageRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
|
||||
class OrderService extends Service
|
||||
{
|
||||
protected $companyRepository;
|
||||
protected $packageRepository;
|
||||
protected $orderRepository;
|
||||
|
||||
public static $classes = [
|
||||
\App\Domains\Virtual\Repositories\OrderCardRepository::class,
|
||||
\App\Domains\Virtual\Repositories\OrderRenewalCardRepository::class,
|
||||
\App\Domains\Virtual\Repositories\OrderRenewalPackageCardRepository::class,
|
||||
\App\Domains\Virtual\Repositories\OrderFlowPackageCardsRepository::class,
|
||||
];
|
||||
protected $orderCardPartitionRepository;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
@ -30,11 +25,13 @@ class OrderService extends Service
|
||||
public function __construct(
|
||||
CompanyRepository $companyRepository,
|
||||
PackageRepository $packageRepository,
|
||||
OrderRepository $orderRepository
|
||||
OrderRepository $orderRepository,
|
||||
OrderCardPartitionRepository $orderCardPartitionRepository
|
||||
) {
|
||||
$this->companyRepository = $companyRepository;
|
||||
$this->packageRepository = $packageRepository;
|
||||
$this->orderRepository = $orderRepository;
|
||||
$this->orderCardPartitionRepository = $orderCardPartitionRepository;
|
||||
}
|
||||
|
||||
|
||||
@ -45,11 +42,7 @@ class OrderService extends Service
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
if (!$class = self::$classes[$conditions['type']]) {
|
||||
throw new NotAllowedException('统计类型不存在');
|
||||
}
|
||||
|
||||
$repository = app($class);
|
||||
$repository = $this->orderCardPartitionRepository->where('type', $conditions['type']);
|
||||
|
||||
$conditions['source'] = 1;
|
||||
|
||||
@ -72,7 +65,7 @@ class OrderService extends Service
|
||||
|
||||
$order_ids = [];
|
||||
|
||||
foreach($orders as $order){
|
||||
foreach ($orders as $order) {
|
||||
$ids = str_to_array($order->order_id);
|
||||
$order_ids = array_merge($order_ids, str_to_array($order->order_id));
|
||||
}
|
||||
@ -94,7 +87,7 @@ class OrderService extends Service
|
||||
|
||||
$item->members = 0;
|
||||
|
||||
foreach($order_ids as $id){
|
||||
foreach ($order_ids as $id) {
|
||||
$item->members += $members[$id]['counts'] ?? 0;
|
||||
}
|
||||
|
||||
@ -111,11 +104,7 @@ class OrderService extends Service
|
||||
*/
|
||||
public function detail(array $conditions = [])
|
||||
{
|
||||
if (!$class = self::$classes[$conditions['type']]) {
|
||||
throw new NotAllowedException('统计类型不存在');
|
||||
}
|
||||
|
||||
$repository = app($class);
|
||||
$repository = $this->orderCardPartitionRepository->where('type', $conditions['type']);
|
||||
|
||||
$cards = $repository->withConditions($conditions)->applyConditions()->paginate($conditions['limit']);
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Commands\Sync;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Domains\Virtual\Jobs\CardSyncJob;
|
||||
use App\Domains\Config\Services\ConfigService;
|
||||
|
||||
class CardSync extends Command
|
||||
{
|
||||
protected $name = 'virtual:sync-card';
|
||||
|
||||
protected $description = '同步VD卡信息数据';
|
||||
|
||||
const CURSOR_KEY = 'sync_card_cursor';
|
||||
|
||||
protected $limit = 1000;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$maxId = app(ConfigService::class)->get(self::CURSOR_KEY) ?: 0;
|
||||
|
||||
$query = DB::connection('vd_old')->table('ckb_custom')->where('id', '>', $maxId)->orderBy('id');
|
||||
|
||||
$nextId = $query->max('id');
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
$this->line('待同步条数:' . $total);
|
||||
|
||||
if ($total) {
|
||||
Artisan::call('real:sync-bloc');
|
||||
}
|
||||
|
||||
$page = 2;
|
||||
|
||||
$jobs = new Collection();
|
||||
|
||||
while ($total) {
|
||||
if (($page - 1) * $this->limit >= $total) {
|
||||
break;
|
||||
}
|
||||
|
||||
$jobs->push(new CardSyncJob($page, $this->limit, $maxId));
|
||||
|
||||
$page++;
|
||||
}
|
||||
|
||||
$total && CardSyncJob::withChain($jobs->toArray())
|
||||
->dispatch(1, $this->limit, $maxId)
|
||||
->allOnQueue('sync');
|
||||
|
||||
$nextId && app(ConfigService::class)->set(self::CURSOR_KEY, $nextId);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Commands\Sync;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Domains\Virtual\Jobs\LogSyncJob;
|
||||
use App\Domains\Config\Services\ConfigService;
|
||||
|
||||
class LogSync extends Command
|
||||
{
|
||||
protected $name = 'virtual:sync-log';
|
||||
|
||||
protected $description = '同步VD订单数据';
|
||||
|
||||
const CURSOR_KEY = 'sync_log_cursor';
|
||||
|
||||
protected $limit = 100;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$maxId = app(ConfigService::class)->get(self::CURSOR_KEY) ?: 0;
|
||||
|
||||
$query = DB::connection('vd_old')->table('logs')->whereIn('type', array_keys(LogSyncJob::$types))
|
||||
->where('id', '>', $maxId)->orderBy('id');
|
||||
|
||||
$nextId = $query->max('id');
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
$this->line('待同步条数:'.$total);
|
||||
|
||||
if ($total) {
|
||||
Artisan::call('virtual:sync-company');
|
||||
Artisan::call('virtual:sync-package');
|
||||
Artisan::call('virtual:sync-product');
|
||||
}
|
||||
|
||||
$page = 2;
|
||||
|
||||
$jobs = new Collection();
|
||||
|
||||
while ($total) {
|
||||
if (($page - 1) * $this->limit >= $total) {
|
||||
break;
|
||||
}
|
||||
|
||||
$jobs->push(new LogSyncJob($page, $this->limit, $maxId));
|
||||
|
||||
$page++;
|
||||
}
|
||||
|
||||
$total && LogSyncJob::withChain($jobs->toArray())
|
||||
->dispatch(1, $this->limit, $maxId)
|
||||
->allOnQueue('sync');
|
||||
|
||||
$nextId && app(ConfigService::class)->set(self::CURSOR_KEY, $nextId);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Domains\Virtual\Services\CardService;
|
||||
use Dipper\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use App\Domains\Virtual\Repositories\OrderCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
|
||||
class CardExport extends AbstractExport implements FromQuery, WithHeadings, WithRows, WithColumnFormatting
|
||||
{
|
||||
@ -25,7 +25,8 @@ class CardExport extends AbstractExport implements FromQuery, WithHeadings, With
|
||||
|
||||
public function query()
|
||||
{
|
||||
$builder = app(OrderCardRepository::class)->forceNoReset()->select([
|
||||
$this->conditions['type'] = 0;
|
||||
$builder = app(OrderCardPartitionRepository::class)->forceNoReset()->select([
|
||||
'*',
|
||||
DB::raw('timelines_json(sim) as timelines'),
|
||||
])->withConditions($this->conditions)->applyConditions();
|
||||
|
@ -6,7 +6,7 @@ use Illuminate\Http\Request;
|
||||
use App\Domains\Virtual\Exports\CardExport;
|
||||
use App\Domains\Virtual\Services\CardService;
|
||||
use App\Domains\Export\Services\ExportService;
|
||||
use App\Domains\Virtual\Repositories\OrderCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
|
||||
class CardController extends Controller
|
||||
{
|
||||
@ -54,7 +54,8 @@ class CardController extends Controller
|
||||
$conditions['id'] = intval(str_replace('No', '', $conditions['id']));
|
||||
}
|
||||
|
||||
$total = app(OrderCardRepository::class)->withConditions($conditions)->applyConditions()->count();
|
||||
$conditions['type'] = 0;
|
||||
$total = app(OrderCardPartitionRepository::class)->withConditions($conditions)->applyConditions()->count();
|
||||
|
||||
try {
|
||||
$export = new CardExport($conditions);
|
||||
|
@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Jobs;
|
||||
|
||||
use App\Models\Card\Card;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Dipper\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use App\Domains\Config\Services\ConfigService;
|
||||
use App\Domains\Virtual\Commands\Sync\CardSync;
|
||||
use App\Domains\Card\Repositories\BlocRepository;
|
||||
use App\Domains\Card\Repositories\CardRepository;
|
||||
|
||||
class CardSyncJob implements ShouldQueue
|
||||
{
|
||||
use Queueable, Dispatchable;
|
||||
|
||||
public $page;
|
||||
public $limit;
|
||||
public $maxId;
|
||||
|
||||
protected static $carrierOperators = [10 => 0, 11 => 1, 12 => 2];
|
||||
|
||||
protected $blocs;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param int $maxId
|
||||
*/
|
||||
public function __construct($page, $limit, $maxId)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->limit = $limit;
|
||||
$this->maxId = $maxId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::info("CardSyncJob #: maxId {$this->maxId} - page {$this->page}");
|
||||
|
||||
$blocs = app(BlocRepository::class)->withTrashed()->get()->pluck('id', 'shorthand')->toArray();
|
||||
|
||||
$query = DB::connection('vd_old')->table('ckb_custom')
|
||||
->select(['id', 'custom_no', 'imsi', 'carrieroperator', 'iccid', 'card_number', 'card_from', 'iccid', 'company', 'custom_state', 'create_time' ,'update_time', 'card_cycle_start'])
|
||||
->where('id', '>', $this->maxId)
|
||||
->orderBy('id');
|
||||
|
||||
$res = $query->forPage($this->page, $this->limit)->get();
|
||||
|
||||
if (empty($res)) {
|
||||
Log::notice('CardSyncJob not result!');
|
||||
return ;
|
||||
}
|
||||
|
||||
$array = [];
|
||||
|
||||
foreach ($res as $key => $value) {
|
||||
$value = (array)$value;
|
||||
|
||||
$virtual_activated_at = date('Y-m-d H:i:s', $value['card_cycle_start']);
|
||||
|
||||
if (Carbon::parse($virtual_activated_at) < Carbon::parse('2000-01-01 00:00:00')) {
|
||||
$virtual_activated_at = null;
|
||||
}
|
||||
|
||||
$array[] = [
|
||||
'sim' => $value['card_number'],
|
||||
'imsi' => $value['imsi'],
|
||||
'iccid' => $value['iccid'],
|
||||
'bloc_id' => $this->blocs[$value['card_from']] ?? 0,
|
||||
'carrier_operator' => self::$carrierOperators[$value['carrieroperator']] ?? 255,
|
||||
'type' => ($value['card_number'][3] >= 5) ? 1 : 0,
|
||||
'activated_at' => $virtual_activated_at,
|
||||
'virtual_activated_at' => $virtual_activated_at,
|
||||
'cancelled_at' => ($value['custom_state'] === 13) ? date('Y-m-d H:i:s', $value['update_time']) : null,
|
||||
'created_at' => date('Y-m-d H:i:s', $value['create_time']),
|
||||
'updated_at' => date('Y-m-d H:i:s', $value['update_time']),
|
||||
];
|
||||
}
|
||||
|
||||
$builder = Card::query()->toBase();
|
||||
|
||||
$sql = $builder->getGrammar()->compileInsert($builder, $array);
|
||||
|
||||
$sql .= ' on conflict (sim) do update set
|
||||
activated_at=COALESCE(cards.activated_at, excluded.virtual_activated_at),
|
||||
virtual_activated_at=excluded.virtual_activated_at,
|
||||
cancelled_at=excluded.cancelled_at';
|
||||
|
||||
$builder->connection->insert($sql, Arr::flatten($array, 1));
|
||||
|
||||
app(CardRepository::class)->forgetCached();
|
||||
|
||||
Log::info("CardSyncJob END #: maxId {$this->maxId} - page {$this->page}");
|
||||
}
|
||||
}
|
@ -1,246 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Jobs;
|
||||
|
||||
use App\Models\Card\Card;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\Virtual\Order;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Dipper\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Models\Virtual\OrderCardPartition;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use App\Domains\Config\Services\ConfigService;
|
||||
use App\Domains\Virtual\Commands\Sync\LogSync;
|
||||
use App\Domains\Virtual\Services\CommonService;
|
||||
use App\Domains\Virtual\Services\ProductService;
|
||||
use App\Domains\Card\Repositories\CardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderRepository;
|
||||
use App\Domains\Virtual\Repositories\CompanyRepository;
|
||||
use App\Domains\Virtual\Repositories\PackageRepository;
|
||||
use App\Domains\Virtual\Repositories\ProductRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderRenewalCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderFlowPackageCardsRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderRenewalPackageCardRepository;
|
||||
|
||||
class LogSyncJob implements ShouldQueue
|
||||
{
|
||||
use Queueable, Dispatchable;
|
||||
|
||||
public $page;
|
||||
public $limit;
|
||||
public $maxId;
|
||||
|
||||
protected $packages;
|
||||
protected $products;
|
||||
protected $companies;
|
||||
|
||||
public static $types = [11 => 1, 13 => 0, 14 => 2, 15 => 3];
|
||||
protected static $carrierOperators = [10 => 0, 11 => 1, 12 => 2];
|
||||
protected static $payChannels = [10 => 'wx', 11 => 'alipay', 12 => 'bank'];
|
||||
|
||||
protected static $orderClasses = [
|
||||
\App\Models\Virtual\OrderCard::class,
|
||||
\App\Models\Virtual\OrderRenewalCard::class,
|
||||
\App\Models\Virtual\OrderRenewalPackageCard::class,
|
||||
\App\Models\Virtual\OrderFlowPackageCards::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param int $maxId
|
||||
*/
|
||||
public function __construct($page, $limit, $maxId)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->limit = $limit;
|
||||
$this->maxId = $maxId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::info("LogSyncJob #: maxId {$this->maxId} - page {$this->page}");
|
||||
$this->packages = app(PackageRepository::class)->withTrashed()->get()->keyBy('sn');
|
||||
$this->products = app(ProductRepository::class)->withTrashed()->get()->keyBy('sn');
|
||||
$this->companies = app(CompanyRepository::class)->withTrashed()->get()->keyBy('sn');
|
||||
|
||||
$query = DB::connection('vd_old')->table('logs')->whereIn('type', array_keys(self::$types))
|
||||
->where('id', '>', $this->maxId)->orderBy('id');
|
||||
|
||||
$res = $query->forPage($this->page, $this->limit)->get();
|
||||
|
||||
if (empty($res)) {
|
||||
Log::notice('LogSyncJob not result!');
|
||||
return ;
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$orderArray = [];
|
||||
$relationArray = [];
|
||||
|
||||
foreach ($res as $key => $value) {
|
||||
$value = (array)$value;
|
||||
|
||||
$package = $this->getPackage($value['content']);
|
||||
$company = $this->getCompany(CommonService::stringifyCompanyId($value['company']));
|
||||
$unit_price = intval($value['order_account'] * 100);
|
||||
$product = $this->getProduct($package, $company['id'], $value['order_account']);
|
||||
$type = self::$types[$value['type']];
|
||||
$pay_channel = self::$payChannels[$value['pay_type']];
|
||||
|
||||
// 按规则生成订单编号 (月6+类型1+公司3+套餐4+价格6)
|
||||
$sn = date('Ym', $value['create_time']) . $type . sprintf('%03d', $company['id']) . sprintf('%04d', $package['id']) . sprintf('%06d', $unit_price);
|
||||
|
||||
$counts = isset($orderArray[$sn]) ? $orderArray[$sn]['counts'] + 1 : 1;
|
||||
$total_price = isset($orderArray[$sn]) ? $orderArray[$sn]['total_price'] + $unit_price : $unit_price;
|
||||
|
||||
$orderArray[$sn] = [
|
||||
'sn' => $sn,
|
||||
'source' => 1,
|
||||
'type' => $type,
|
||||
'company_id' => $company['id'],
|
||||
'package_id' => $package['id'],
|
||||
'product_id' => $product['id'],
|
||||
'pay_channel' => $pay_channel,
|
||||
'unit_price' => $unit_price,
|
||||
'counts' => $counts,
|
||||
'total_price' => $total_price,
|
||||
'custom_price' => $total_price,
|
||||
'order_at' => date('Y-m-d H:i:s', $value['create_time']),
|
||||
'order_status' => 4,
|
||||
'transaction_status' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s', $value['create_time']),
|
||||
];
|
||||
|
||||
$k = $sn . '-' . $value['sim'];
|
||||
|
||||
$counts = isset($relationArray[$k]) ? $relationArray[$k]['counts'] + 1 : 1;
|
||||
|
||||
$relationArray[$k] = [
|
||||
'order_sn' => $sn,
|
||||
'type' => $type,
|
||||
'sim' => $value['sim'],
|
||||
'company_id' => $company['id'],
|
||||
'package_id' => $package['id'],
|
||||
'counts' => $counts,
|
||||
'created_at' => date('Y-m-d H:i:s', $value['create_time']),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$builder = Order::query()->toBase();
|
||||
|
||||
$sql = $builder->getGrammar()->compileInsert($builder, $orderArray);
|
||||
|
||||
$sql .= " on conflict (sn, COALESCE(deleted_at, '1970-01-01 08:00:00'::timestamp)) do update set
|
||||
counts=virtual_orders.counts + excluded.counts,
|
||||
total_price=virtual_orders.unit_price * (virtual_orders.counts + excluded.counts),
|
||||
custom_price=virtual_orders.unit_price * (virtual_orders.counts + excluded.counts)";
|
||||
|
||||
$builder->connection->insert($sql, Arr::flatten($orderArray, 1));
|
||||
|
||||
$orders = Order::withTrashed()->select(['id', 'sn'])->whereIn('sn', array_pluck($orderArray, 'sn'))->get()->pluck('id', 'sn')->toArray();
|
||||
|
||||
foreach ($relationArray as $key => $value) {
|
||||
$relationArray[$key]['order_id'] = $orders[$value['order_sn']];
|
||||
unset($relationArray[$key]['order_sn']);
|
||||
}
|
||||
|
||||
$relationArray = array_groupBy($relationArray, 'type');
|
||||
|
||||
foreach ($relationArray as $type => $array) {
|
||||
$class = new self::$orderClasses[$type];
|
||||
$builder = $class->query()->toBase();
|
||||
|
||||
$sql = $builder->getGrammar()->compileInsert($builder, $array);
|
||||
|
||||
$sql .= " on conflict (order_id, sim, COALESCE(deleted_at, '1970-01-01 08:00:00'::timestamp)) do update set
|
||||
counts={$class->getTable()}.counts + excluded.counts";
|
||||
|
||||
$builder->connection->insert($sql, Arr::flatten($array, 1));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
Log::info("LogSyncJob ERROR #: maxId {$this->maxId} - page {$this->page}");
|
||||
throw $e;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
app(OrderRepository::class)->forgetCached();
|
||||
app(OrderCardRepository::class)->forgetCached();
|
||||
app(OrderRenewalCardRepository::class)->forgetCached();
|
||||
app(OrderRenewalPackageCardRepository::class)->forgetCached();
|
||||
app(OrderFlowPackageCardsRepository::class)->forgetCached();
|
||||
app(OrderCardPartitionRepository::class)->forgetCached();
|
||||
|
||||
Log::info("LogSyncJob END #: maxId {$this->maxId} - page {$this->page}");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取套餐
|
||||
*
|
||||
* @param string $sn
|
||||
* @return void
|
||||
*/
|
||||
protected function getCompany($sn)
|
||||
{
|
||||
if (!$company = $this->companies[$sn]) {
|
||||
throw new \Exception('企业不存在');
|
||||
}
|
||||
|
||||
return $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取套餐
|
||||
*
|
||||
* @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, $orderAccount)
|
||||
{
|
||||
$price = intval($orderAccount * 100);
|
||||
$sn = ProductService::sn($package['sn'], $companyId, $price);
|
||||
|
||||
if (!$product = $this->products[$sn]) {
|
||||
$product = app(ProductService::class)->store([
|
||||
'name' => $package['name'] . ' ' . $orderAccount,
|
||||
'company_id' => $companyId,
|
||||
'package_id' => $package['id'],
|
||||
'price' => $price,
|
||||
]);
|
||||
$this->products[$sn] = $product;
|
||||
app(ProductRepository::class)->forgetCached();
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
}
|
@ -25,8 +25,6 @@ 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,
|
||||
\App\Domains\Virtual\Commands\Sync\LogSync::class,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Repositories;
|
||||
|
||||
use App\Core\Repository;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\Virtual\Order as Model;
|
||||
use App\Domains\Virtual\Services\CommonService;
|
||||
|
||||
class AddedOrderRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* 是否关闭缓存
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $cacheSkip = false;
|
||||
|
||||
/**
|
||||
* 是否开启数据转化
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needTransform = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldSearchable = [
|
||||
'id' => '=',
|
||||
'sn' => 'like',
|
||||
'package.name' => 'like',
|
||||
];
|
||||
|
||||
public function model()
|
||||
{
|
||||
return Model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据格式化
|
||||
*
|
||||
* @param mixed $result
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transform($model)
|
||||
{
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withConditions(array $conditions = [])
|
||||
{
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
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', '>=', Carbon::parse($conditions['starttime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['endtime'])) {
|
||||
$this->model = $this->model->where('order_at', '<=', Carbon::parse($conditions['endtime']));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -7,11 +7,11 @@ use App\Models\Card\Card;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Domains\Card\Repositories\CardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
|
||||
class CardService extends Service
|
||||
{
|
||||
protected $orderCardRepository;
|
||||
protected $orderCardPartitionRepository;
|
||||
protected $cardRepository;
|
||||
|
||||
protected static $typeNames = ['基础套餐', '基础续费', '续费包'];
|
||||
@ -21,9 +21,9 @@ class CardService extends Service
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(OrderCardRepository $orderCardRepository, CardRepository $cardRepository)
|
||||
public function __construct(OrderCardPartitionRepository $orderCardPartitionRepository, CardRepository $cardRepository)
|
||||
{
|
||||
$this->orderCardRepository = $orderCardRepository;
|
||||
$this->orderCardPartitionRepository = $orderCardPartitionRepository;
|
||||
$this->cardRepository = $cardRepository;
|
||||
}
|
||||
|
||||
@ -36,8 +36,9 @@ class CardService extends Service
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
$limit = $conditions['limit'] ?? 20;
|
||||
$conditions['type'] = 0;
|
||||
|
||||
$cards = $this->orderCardRepository->select([
|
||||
$cards = $this->orderCardPartitionRepository->select([
|
||||
'*',
|
||||
DB::raw('timelines_json(sim) as timelines'),
|
||||
])->withConditions($conditions)->applyConditions()->paginate($limit);
|
||||
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Real;
|
||||
|
||||
use App\Core\Model;
|
||||
use App\Models\Card\Card;
|
||||
|
||||
/**
|
||||
* App\Models\Real\AddedOrder
|
||||
*
|
||||
* @property int $id 订单ID
|
||||
* @property string $sn 订单编号
|
||||
* @property int $type 订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)
|
||||
* @property int $company_id 企业ID
|
||||
* @property string $transaction_no 交易流水号
|
||||
* @property string $pay_channel 支付频道
|
||||
* @property int $unit_price 单价
|
||||
* @property int $counts 数量
|
||||
* @property int $total_price 总价
|
||||
* @property string|null $order_at 下单时间
|
||||
* @property string|null $remark 订单备注
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property string|null $deleted_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card\Card[] $additionalPackageCards
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card\Card[] $flowPackageCards
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card\Card[] $optionalPackageCards
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card\Card[] $renewalCards
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card\Card[] $renewalPackageCards
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereCompanyId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereCounts($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereOrderAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder wherePayChannel($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereRemark($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereSn($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereTotalPrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereTransactionNo($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereUnitPrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\AddedOrder whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class AddedOrder extends Model
|
||||
{
|
||||
protected $table = 'real_added_orders';
|
||||
|
||||
public function renewalCards()
|
||||
{
|
||||
return $this->belongsToMany(Card::class, 'real_added_order_renewal_cards', 'sim', 'sim');
|
||||
}
|
||||
|
||||
public function renewalPackageCards()
|
||||
{
|
||||
return $this->belongsToMany(Card::class, 'real_added_order_renewal_package_cards', 'sim', 'sim');
|
||||
}
|
||||
|
||||
public function flowPackageCards()
|
||||
{
|
||||
return $this->belongsToMany(Card::class, 'real_added_order_flows_package_cards', 'sim', 'sim');
|
||||
}
|
||||
|
||||
public function optionalPackageCards()
|
||||
{
|
||||
return $this->belongsToMany(Card::class, 'real_added_order_optional_package_cards', 'sim', 'sim');
|
||||
}
|
||||
|
||||
public function additionalPackageCards()
|
||||
{
|
||||
return $this->belongsToMany(Card::class, 'real_added_order_additional_package_cards', 'sim', 'sim');
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Real;
|
||||
|
||||
use App\Core\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* App\Models\Real\OrderCard
|
||||
*
|
||||
* @property int $id 关联表ID
|
||||
* @property int $sim sim号
|
||||
* @property int $order_id 订单ID
|
||||
* @property int $company_id 企业ID
|
||||
* @property int $package_id 套餐ID
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property string|null $deleted_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Order[] $additionalPackageOrders
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Package[] $additionalPackagePackages
|
||||
* @property-read \App\Models\Real\Company $company
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Order[] $flowPackageOrders
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Package[] $flowPackagePackages
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Order[] $optionalPackageOrders
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Package[] $optionalPackagePackages
|
||||
* @property-read \App\Models\Real\Order $order
|
||||
* @property-read \App\Models\Real\Package $package
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Order[] $renewalOrders
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Order[] $renewalPackageOrders
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Package[] $renewalPackagePackages
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Real\Package[] $renewalPackages
|
||||
* @method static bool|null forceDelete()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard newQuery()
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Real\OrderCard onlyTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard query()
|
||||
* @method static bool|null restore()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereCompanyId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereOrderId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard wherePackageId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereSim($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\OrderCard whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Real\OrderCard withTrashed()
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Real\OrderCard withoutTrashed()
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class OrderCard extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'real_order_cards';
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id', 'sim');
|
||||
}
|
||||
|
||||
public function package()
|
||||
{
|
||||
return $this->belongsTo(Package::class, 'package_id', 'sim');
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class, 'order_id', 'sim');
|
||||
}
|
||||
|
||||
// 续费套餐
|
||||
public function renewalPackages()
|
||||
{
|
||||
return $this->belongsToMany(Package::class, 'real_added_order_renewal_cards', 'sim', 'package_id');
|
||||
}
|
||||
|
||||
// 续费包套餐
|
||||
public function renewalPackagePackages()
|
||||
{
|
||||
return $this->belongsToMany(Package::class, 'real_added_order_renewal_package_cards', 'sim', 'package_id');
|
||||
}
|
||||
|
||||
// 加油包套餐
|
||||
public function flowPackagePackages()
|
||||
{
|
||||
return $this->belongsToMany(Package::class, 'real_added_order_flows_package_cards', 'sim', 'package_id');
|
||||
}
|
||||
|
||||
// 可选包套餐
|
||||
public function optionalPackagePackages()
|
||||
{
|
||||
return $this->belongsToMany(Package::class, 'real_added_order_optional_package_cards', 'sim', 'package_id');
|
||||
}
|
||||
|
||||
// 附加包套餐
|
||||
public function additionalPackagePackages()
|
||||
{
|
||||
return $this->belongsToMany(Package::class, 'real_added_order_additional_package_cards', 'sim', 'package_id');
|
||||
}
|
||||
|
||||
// 续费订单
|
||||
public function renewalOrders()
|
||||
{
|
||||
return $this->belongsToMany(Order::class, 'real_added_order_renewal_cards', 'sim', 'order_id');
|
||||
}
|
||||
|
||||
// 续费订单
|
||||
public function renewalPackageOrders()
|
||||
{
|
||||
return $this->belongsToMany(Order::class, 'real_added_order_renewal_package_cards', 'sim', 'order_id');
|
||||
}
|
||||
|
||||
// 加油包订单
|
||||
public function flowPackageOrders()
|
||||
{
|
||||
return $this->belongsToMany(Order::class, 'real_added_order_flows_package_cards', 'sim', 'order_id');
|
||||
}
|
||||
|
||||
// 可选包订单
|
||||
public function optionalPackageOrders()
|
||||
{
|
||||
return $this->belongsToMany(Order::class, 'real_added_order_optional_package_cards', 'sim', 'order_id');
|
||||
}
|
||||
|
||||
// 附加包订单
|
||||
public function additionalPackageOrders()
|
||||
{
|
||||
return $this->belongsToMany(Order::class, 'real_added_order_additional_package_cards', 'sim', 'order_id');
|
||||
}
|
||||
}
|
14
app/Models/Real/OrderCardPartition.php
Normal file
14
app/Models/Real/OrderCardPartition.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Real;
|
||||
|
||||
use App\Core\Model;
|
||||
use App\Models\Real\Relations\OrderRelations;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class OrderCardPartition extends Model
|
||||
{
|
||||
use SoftDeletes, OrderRelations;
|
||||
|
||||
protected $table = 'virtual_order_cards_partition';
|
||||
}
|
31
app/Models/Real/Relations/OrderRelations.php
Normal file
31
app/Models/Real/Relations/OrderRelations.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Real\Relations;
|
||||
|
||||
use App\Models\Card\Card;
|
||||
use App\Models\Real\Order;
|
||||
use App\Models\Real\Company;
|
||||
use App\Models\Real\Package;
|
||||
|
||||
trait OrderRelations
|
||||
{
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
public function package()
|
||||
{
|
||||
return $this->belongsTo(Package::class, 'package_id', 'id');
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class, 'order_id', 'id');
|
||||
}
|
||||
|
||||
public function card()
|
||||
{
|
||||
return $this->belongsTo(Card::class, 'sim', 'sim');
|
||||
}
|
||||
}
|
@ -19,9 +19,10 @@ class CreateRealOrdersTable extends Migration
|
||||
|
||||
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->string('sn', 64)->comment('订单编号');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础订单 1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)');
|
||||
$table->integer('company_id')->unsigned()->default(0)->comment("企业ID");
|
||||
$table->integer('package_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('单价');
|
||||
@ -38,7 +39,7 @@ class CreateRealOrdersTable extends Migration
|
||||
|
||||
$table->unique(['sn', 'deleted_at']);
|
||||
$table->index('type');
|
||||
$table->index('company_id');
|
||||
$table->index(['carrier_operator', 'company_id', 'package_id']);
|
||||
$table->index('order_at');
|
||||
|
||||
$table->comment('RD订单');
|
||||
|
@ -13,23 +13,56 @@ class CreateRealOrderCardsTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('real_order_cards')) {
|
||||
if (Schema::hasTable('real_order_cards_table_partition')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('real_order_cards', function (Blueprint $table) {
|
||||
Schema::create('real_order_cards_table_partition', function (Blueprint $table) {
|
||||
$table->increments('id')->comment('关联表ID');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)');
|
||||
$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->integer('counts')->unsigned()->default(0)->comment('数量');
|
||||
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->comment("RD订单企业套餐卡关联表");
|
||||
|
||||
$table->partition('type', 'list');
|
||||
$table->addPartition('real_order_cards', 'list', [0]);
|
||||
$table->addPartition('real_added_order_renewal_cards', 'list', [1]);
|
||||
$table->addPartition('real_added_order_renewal_package_cards', 'list', [2]);
|
||||
$table->addPartition('real_added_order_flows_package_cards', 'list', [3]);
|
||||
$table->addPartition('real_added_order_optional_package_cards', 'list', [4]);
|
||||
$table->addPartition('real_added_order_additional_package_cards', 'list', [5]);
|
||||
});
|
||||
|
||||
Schema::table('real_order_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
$table->unique(['sim', 'deleted_at']);
|
||||
});
|
||||
|
||||
$table->comment("RD订单企业套餐卡关联表");
|
||||
Schema::table('real_added_order_renewal_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_renewal_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_flows_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_optional_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_additional_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
}
|
||||
|
||||
@ -40,6 +73,6 @@ class CreateRealOrderCardsTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('real_order_cards');
|
||||
Schema::dropIfExists('real_order_cards_table_partition');
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateRealAddedOrdersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('real_added_orders')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('real_added_orders', function (Blueprint $table) {
|
||||
$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('企业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');
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateRealAddedOrderCardsTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('real_added_order_cards_table_partition')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('real_added_order_cards_table_partition', function (Blueprint $table) {
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)');
|
||||
$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->integer('unit_price')->unsigned()->default(0)->comment('单价');
|
||||
$table->integer('counts')->unsigned()->default(0)->comment('数量');
|
||||
$table->timestamps();
|
||||
|
||||
$table->comment("RD续费及增值包订单关联卡");
|
||||
|
||||
$table->partition('type', 'list');
|
||||
$table->addPartition('real_added_order_renewal_cards', 'list', [1]);
|
||||
$table->addPartition('real_added_order_renewal_package_cards', 'list', [2]);
|
||||
$table->addPartition('real_added_order_flows_package_cards', 'list', [3]);
|
||||
$table->addPartition('real_added_order_optional_package_cards', 'list', [4]);
|
||||
$table->addPartition('real_added_order_additional_package_cards', 'list', [5]);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_renewal_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_renewal_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_flows_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_optional_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_added_order_additional_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
// DB::unprepared(File::get(__DIR__ . '/create_real_added_order_cards_table.pgsql'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('real_added_order_cards_table_partition');
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import Vuex from 'vuex';
|
||||
|
||||
import permissions from './module/permissions';
|
||||
import common from './module/common';
|
||||
import order from './module/order';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
@ -12,7 +13,8 @@ const store = new Vuex.Store({
|
||||
strict: debug,
|
||||
modules: {
|
||||
permissions,
|
||||
common
|
||||
common,
|
||||
order
|
||||
}
|
||||
});
|
||||
|
||||
|
27
frontend/src/store/module/order.js
Normal file
27
frontend/src/store/module/order.js
Normal file
@ -0,0 +1,27 @@
|
||||
const state = {
|
||||
real_orders: {},
|
||||
cards: [],
|
||||
selected: []
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
SET_REAL_ORDERS(state, data) {
|
||||
state.real_orders = data;
|
||||
},
|
||||
SET_CARDS(state, data) {
|
||||
state.cards = data;
|
||||
},
|
||||
SET_SELECTED(state, data) {
|
||||
state.selected = data;
|
||||
}
|
||||
};
|
||||
|
||||
const actions = {
|
||||
|
||||
};
|
||||
|
||||
export default {
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
};
|
132
frontend/src/views/virtual/orders/cards.vue
Normal file
132
frontend/src/views/virtual/orders/cards.vue
Normal file
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<Modal
|
||||
:closable="true"
|
||||
:mask-closable="false"
|
||||
:title="'选择流量卡'"
|
||||
@on-visible-change="visibleChange"
|
||||
v-model="my_show"
|
||||
width="1440"
|
||||
>
|
||||
<div class="page-handle-wrap">
|
||||
<ul class="handle-wraper bd-b">
|
||||
<li class="f-l">
|
||||
<div class="text-exp">
|
||||
<b v-if="selected.length">已选{{selected.length}}张</b>
|
||||
<b v-else>全部信息</b>
|
||||
</div>
|
||||
</li>
|
||||
<li class="f-r">
|
||||
<div class="handle-item">
|
||||
<Button @click="search.show=!search.show" ghost icon="ios-search" type="primary">搜索</Button>
|
||||
</div>
|
||||
|
||||
<div class="handle-item">
|
||||
<Button @click="index(1)" icon="md-refresh">刷新</Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="search-wrap" v-show="search.show">
|
||||
<ul class="handle-wraper">
|
||||
<li class="handle-item w-250">
|
||||
<Select clearable placeholder="运营商" v-model="params.carrier_operator">
|
||||
<Option :value="0">联通</Option>
|
||||
<Option :value="1">移动</Option>
|
||||
<Option :value="2">电信</Option>
|
||||
</Select>
|
||||
</li>
|
||||
|
||||
<li class="handle-item w-250">
|
||||
<Select clearable placeholder="使用状态" v-model="params.used">
|
||||
<Option :value="0">未使用</Option>
|
||||
<Option :value="1">已使用</Option>
|
||||
</Select>
|
||||
</li>
|
||||
|
||||
<li class="handle-item w-250">
|
||||
<DatePicker
|
||||
:editable="false"
|
||||
placeholder="请选择时间"
|
||||
placement="bottom-start"
|
||||
type="daterange"
|
||||
v-model.trim="params.time"
|
||||
></DatePicker>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="handle-wraper">
|
||||
<li class="handle-item w-250">
|
||||
<AutoComplete
|
||||
@on-search="handleCompleteCompanies"
|
||||
icon="ios-search"
|
||||
placeholder="企业名称"
|
||||
v-model.trim="params.company_name"
|
||||
>
|
||||
<Option
|
||||
:key="item.id"
|
||||
:value="item.name"
|
||||
v-for="item in completeHandledCompanies"
|
||||
>{{ item.name }}</Option>
|
||||
</AutoComplete>
|
||||
</li>
|
||||
|
||||
<li class="handle-item w-250">
|
||||
<AutoComplete
|
||||
@on-search="handleCompletePackages(type)"
|
||||
icon="ios-search"
|
||||
placeholder="套餐名称"
|
||||
v-model.trim="params.package_name"
|
||||
>
|
||||
<Option
|
||||
:key="item.id"
|
||||
:value="item.name"
|
||||
v-for="item in completeHandledPackages"
|
||||
>{{ item.name }}</Option>
|
||||
</AutoComplete>
|
||||
</li>
|
||||
|
||||
<li class="handle-item w-250">
|
||||
<Input placeholder="SIM" type="textarea" v-model="params.sim"/>
|
||||
</li>
|
||||
|
||||
<li class="f-r">
|
||||
<div class="handle-item">
|
||||
<Button @click="index(1)" ghost type="primary">立即搜索</Button>
|
||||
</div>
|
||||
<div class="handle-item">
|
||||
<Button @click="resetSearch" ghost type="warning">重置搜索</Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-list-wrap">
|
||||
<Row>
|
||||
<Col span="16">
|
||||
<Table
|
||||
ref="orderSelection"
|
||||
size="small"
|
||||
:columns="orderColumns"
|
||||
:data="orders ? orders.data : []"
|
||||
></Table>
|
||||
</Col>
|
||||
<Col offset="1" span="7">
|
||||
<Table
|
||||
ref="cardSelection"
|
||||
:columns="cardColumns"
|
||||
size="small"
|
||||
:data="cards ? cards.data : []"
|
||||
></Table>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
||||
<footer class="ta-c" slot="footer">
|
||||
<Button @click="clear" class="w-80 umar-r5" ghost type="primary">取消</Button>
|
||||
<Button :loading="loading" @click="ok" class="w-80" type="primary">提交</Button>
|
||||
</footer>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script src="./js/cards.js"></script>
|
@ -131,6 +131,7 @@
|
||||
</div>
|
||||
|
||||
<div class="ta-c">
|
||||
<Button @click="cards" class="w-80 umar-r5" ghost type="success">选卡</Button>
|
||||
<Button @click="clear" class="w-80 umar-r5" ghost type="primary">取消</Button>
|
||||
<Button :loading="loading" @click="ok" class="w-80" type="primary">提交</Button>
|
||||
</div>
|
||||
|
@ -130,9 +130,12 @@
|
||||
:type="type"
|
||||
@add-success="index"
|
||||
@update-success="index(list_data.current_page)"
|
||||
@select-cards="openCards(true)"
|
||||
></ui-edit>
|
||||
|
||||
<ui-detail :data="detailObj.data" :show.sync="detailObj.show"></ui-detail>
|
||||
|
||||
<ui-cards :show.sync="cardsObj.show" :type="type" @select-success="selectedCards"></ui-cards>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
133
frontend/src/views/virtual/orders/js/cards.js
Normal file
133
frontend/src/views/virtual/orders/js/cards.js
Normal file
@ -0,0 +1,133 @@
|
||||
import * as API from 'api/virtual/orders';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
type: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
my_show: false,
|
||||
loading: false,
|
||||
search: {
|
||||
show: true
|
||||
},
|
||||
params: {
|
||||
company_id: '',
|
||||
package_id: '',
|
||||
carrier_operator: '',
|
||||
time: [],
|
||||
used: 0,
|
||||
sim: ''
|
||||
},
|
||||
orders: [],
|
||||
cards: [],
|
||||
selected: [],
|
||||
orderColumns: [
|
||||
{
|
||||
type: 'selection',
|
||||
width: 60,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '订单编号',
|
||||
key: 'sn'
|
||||
},
|
||||
{
|
||||
title: '企业名称',
|
||||
key: 'company_name'
|
||||
},
|
||||
{
|
||||
title: '运营商',
|
||||
key: 'carrier_operator_name'
|
||||
},
|
||||
{
|
||||
title: '套餐名称',
|
||||
key: 'package_name'
|
||||
},
|
||||
{
|
||||
title: '订单卡量',
|
||||
key: 'counts'
|
||||
},
|
||||
{
|
||||
title: '订单金额',
|
||||
key: 'total_price'
|
||||
},
|
||||
{
|
||||
title: '支付方式',
|
||||
key: 'pay_chanel_name'
|
||||
},
|
||||
{
|
||||
title: '订单时间',
|
||||
key: 'order_at'
|
||||
},
|
||||
{
|
||||
title: '所需卡量',
|
||||
key: ''
|
||||
}
|
||||
],
|
||||
cardColumns: [
|
||||
{
|
||||
type: 'selection',
|
||||
width: 60,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: 'SIM',
|
||||
key: 'sim'
|
||||
},
|
||||
{
|
||||
title: 'VD企业',
|
||||
key: 'company_name'
|
||||
},
|
||||
{
|
||||
title: 'VD套餐',
|
||||
key: 'package_name'
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
key: 'used_name'
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
show(bool) {
|
||||
this.my_show = bool;
|
||||
if (bool) {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
ok() {
|
||||
|
||||
},
|
||||
index(page) {},
|
||||
|
||||
visibleChange(bool) {
|
||||
if (!bool) {
|
||||
this.$emit('update:show', false);
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
this.my_show = false;
|
||||
},
|
||||
resetSearch() {
|
||||
for (let k in this.params) {
|
||||
if (k === 'time') {
|
||||
this.params[k] = [];
|
||||
} else if (k === 'used') {
|
||||
this.params[k] = 0;
|
||||
} else {
|
||||
this.params[k] = '';
|
||||
}
|
||||
}
|
||||
this.index(1);
|
||||
}
|
||||
}
|
||||
};
|
@ -165,9 +165,9 @@ export default {
|
||||
this.params.carrier_operator = selectPackage.carrier_operator;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(type);
|
||||
console.log(selectPackage);
|
||||
},
|
||||
cards() {
|
||||
this.$emit('select-cards');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -4,7 +4,8 @@ export default {
|
||||
name: 'Orders',
|
||||
components: {
|
||||
UiEdit: resolve => require(['views/virtual/orders/edit'], resolve),
|
||||
UiDetail: resolve => require(['views/virtual/orders/detail'], resolve)
|
||||
UiDetail: resolve => require(['views/virtual/orders/detail'], resolve),
|
||||
UiCards: resolve => require(['views/virtual/orders/cards'], resolve)
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -27,6 +28,9 @@ export default {
|
||||
show: false,
|
||||
data: null
|
||||
},
|
||||
cardsObj: {
|
||||
show: false
|
||||
},
|
||||
search: {
|
||||
show: false
|
||||
},
|
||||
@ -71,7 +75,11 @@ export default {
|
||||
title: '订单数量',
|
||||
key: '',
|
||||
width: 100,
|
||||
render: (h, { row, column, index }) => {
|
||||
render: (h, {
|
||||
row,
|
||||
column,
|
||||
index
|
||||
}) => {
|
||||
return h('span', Number(row.counts));
|
||||
}
|
||||
},
|
||||
@ -84,19 +92,31 @@ export default {
|
||||
title: '已排单数',
|
||||
key: '',
|
||||
width: 100,
|
||||
render: (h, { row, column, index }) => {
|
||||
render: (h, {
|
||||
row,
|
||||
column,
|
||||
index
|
||||
}) => {
|
||||
let style = {};
|
||||
if (row.shipments !== row.counts) {
|
||||
style = { 'color': '#ed4014' };
|
||||
style = {
|
||||
'color': '#ed4014'
|
||||
};
|
||||
}
|
||||
return h('span', { style }, Number(row.shipments));
|
||||
return h('span', {
|
||||
style
|
||||
}, Number(row.shipments));
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '订单状态',
|
||||
key: '',
|
||||
width: 100,
|
||||
render: (h, { row, column, index }) => {
|
||||
render: (h, {
|
||||
row,
|
||||
column,
|
||||
index
|
||||
}) => {
|
||||
let html = [];
|
||||
|
||||
html.push(h('Button', {
|
||||
@ -113,7 +133,11 @@ export default {
|
||||
title: '收款状态',
|
||||
key: '',
|
||||
width: 100,
|
||||
render: (h, { row, column, index }) => {
|
||||
render: (h, {
|
||||
row,
|
||||
column,
|
||||
index
|
||||
}) => {
|
||||
let status = ['info', 'success', 'error'];
|
||||
|
||||
let html = [];
|
||||
@ -145,7 +169,11 @@ export default {
|
||||
let html = [];
|
||||
|
||||
if (row.deleted_at) {
|
||||
return h('Tag', { props: { color: 'default' } }, '该订单已被删除');
|
||||
return h('Tag', {
|
||||
props: {
|
||||
color: 'default'
|
||||
}
|
||||
}, '该订单已被删除');
|
||||
}
|
||||
|
||||
if (this.haveJurisdiction('show')) {
|
||||
@ -168,14 +196,16 @@ export default {
|
||||
data: res.data
|
||||
};
|
||||
}
|
||||
}).catch(() => { this.isShowLoading(false); });
|
||||
}).catch(() => {
|
||||
this.isShowLoading(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, '查看'));
|
||||
}
|
||||
|
||||
if (this.haveJurisdiction('update')) {
|
||||
// 未收款 -> 已收款
|
||||
// 未收款 -> 已收款
|
||||
if (row.transaction_status === 0) {
|
||||
html.push(h('Button', {
|
||||
props: {
|
||||
@ -224,8 +254,18 @@ export default {
|
||||
let refundHtml = [];
|
||||
|
||||
let Options = [];
|
||||
Options.push(h('Option', { props: { key: 'bank', value: 'bank' } }, '银行转账'));
|
||||
Options.push(h('Option', { props: { key: 'alipay', value: 'alipay' } }, '支付宝转账'));
|
||||
Options.push(h('Option', {
|
||||
props: {
|
||||
key: 'bank',
|
||||
value: 'bank'
|
||||
}
|
||||
}, '银行转账'));
|
||||
Options.push(h('Option', {
|
||||
props: {
|
||||
key: 'alipay',
|
||||
value: 'alipay'
|
||||
}
|
||||
}, '支付宝转账'));
|
||||
|
||||
refundHtml.push(h('Select', {
|
||||
props: {
|
||||
@ -406,7 +446,12 @@ export default {
|
||||
render: (h) => {
|
||||
let Options = [];
|
||||
for (const key in logistics) {
|
||||
Options.push(h('Option', { props: { key: key, value: key } }, logistics[key]));
|
||||
Options.push(h('Option', {
|
||||
props: {
|
||||
key: key,
|
||||
value: key
|
||||
}
|
||||
}, logistics[key]));
|
||||
}
|
||||
|
||||
let Select = h('Select', {
|
||||
@ -509,7 +554,9 @@ export default {
|
||||
index(page = 1) {
|
||||
this.type = Number(this.$route.params.type);
|
||||
this.params.type = Number(this.$route.params.type);
|
||||
let data = this.searchDataHandle({}, { page }, this.params);
|
||||
let data = this.searchDataHandle({}, {
|
||||
page
|
||||
}, this.params);
|
||||
this.isShowLoading(true);
|
||||
API.index(data).then(res => {
|
||||
this.isShowLoading(false);
|
||||
@ -570,6 +617,18 @@ export default {
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* [openCards 打开选卡弹窗]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
openCards(bool) {
|
||||
this.cardsObj = {
|
||||
show: bool
|
||||
};
|
||||
},
|
||||
selectedCards() {
|
||||
console.log(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||
|
120
tests/SchemaTest.php
Normal file
120
tests/SchemaTest.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||
|
||||
Schema::dropIfExists('real_packages');
|
||||
Schema::dropIfExists('real_orders');
|
||||
Schema::dropIfExists('real_added_orders');
|
||||
Schema::dropIfExists('real_order_cards');
|
||||
Schema::dropIfExists('real_add_order_cards_table_partition');
|
||||
Schema::dropIfExists('real_order_cards_table_partition');
|
||||
|
||||
Schema::create('real_packages', function (Blueprint $table) {
|
||||
$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('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套餐");
|
||||
});
|
||||
|
||||
Schema::create('real_orders', function (Blueprint $table) {
|
||||
$table->increments('id')->comment('订单ID');
|
||||
$table->string('sn', 64)->comment('订单编号');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础订单 1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)');
|
||||
$table->integer('company_id')->unsigned()->default(0)->comment("企业ID");
|
||||
$table->integer('package_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', 'package_id']);
|
||||
$table->index('order_at');
|
||||
|
||||
$table->comment('RD订单');
|
||||
});
|
||||
|
||||
Schema::create('real_order_cards_table_partition', function (Blueprint $table) {
|
||||
$table->increments('id')->comment('关联表ID');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)');
|
||||
$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->integer('counts')->unsigned()->default(0)->comment('数量');
|
||||
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->comment("RD订单企业套餐卡关联表");
|
||||
|
||||
$table->partition('type', 'list');
|
||||
$table->addPartition('real_order_cards', 'list', [0]);
|
||||
$table->addPartition('real_order_renewal_cards', 'list', [1]);
|
||||
$table->addPartition('real_order_renewal_package_cards', 'list', [2]);
|
||||
$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]);
|
||||
});
|
||||
|
||||
Schema::table('real_order_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
$table->unique(['sim', 'deleted_at']);
|
||||
});
|
||||
|
||||
Schema::table('real_order_renewal_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_order_renewal_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_order_flows_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_order_optional_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
||||
|
||||
Schema::table('real_order_additional_package_cards', function (Blueprint $table) {
|
||||
$table->unique(['sim', 'order_id']);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user