代理商配置

This commit is contained in:
邓皓元 2020-01-06 21:51:10 +08:00
parent af79fd0439
commit d070a45101
17 changed files with 407 additions and 17 deletions

View File

@ -8,6 +8,7 @@ use App\Domains\Export\Services\ImportService;
use App\Domains\Virtual\Exports\PropertyExport;
use App\Domains\Virtual\Services\PropertyService;
use App\Domains\Virtual\Repositories\PropertySettingRepository;
use App\Domains\Virtual\Services\AgentService;
use App\Exceptions\InvalidArgumentException;
class PropertyController extends Controller
@ -42,6 +43,17 @@ class PropertyController extends Controller
}
}
/**
* 代理商配置.
*
* @return \Illuminate\Http\Response
*/
public function agents()
{
$res = app(AgentService::class)->listGroupByCompanyId();
return res($res, '代理商配置', 201);
}
/**
* 列表.
*

View File

@ -56,6 +56,7 @@ $router->group(['prefix' => 'virtual', 'as' => 'virtual', 'middleware' => ['admi
$router->post('/properties/store', ['as' => 'properties.store', 'uses' => 'PropertyController@store']);
$router->get('/properties/export', ['as' => 'properties.export', 'uses' => 'PropertyController@export']);
$router->post('/properties/import', ['as' => 'properties.import', 'uses' => 'PropertyController@import']);
$router->get('/properties/agents', ['as' => 'properties.agents', 'uses' => 'PropertyController@agents']);
// 订单管理
$router->addRoute(['GET', 'POST'], '/orders/index', ['as' => 'orders.index', 'uses' => 'OrderController@index']);

View File

@ -118,12 +118,12 @@ class AgentService extends Service
return true;
}
public static function load($id)
public static function listGroupByCompanyId()
{
if (!self::$agents) {
self::$agents = app(AgentRepository::class)->select(['id', 'name', 'status'])->withTrashed()->get()->keyBy('id')->toArray();
self::$agents = app(AgentRepository::class)->select(['id', 'company_id', 'name', 'status'])->withTrashed()->get()->groupBy('company_id')->toArray();
}
return self::$agents[$id];
return self::$agents;
}
}

View File

@ -27,7 +27,8 @@ class PropertyService extends Service
'customer' => '客户类型',
'package' => '套餐分类',
'province' => '省份设置',
'package_type' => '套餐类型'
'package_type' => '套餐类型',
'agent' => '代理商设置',
];
public static $default = [
@ -40,6 +41,8 @@ class PropertyService extends Service
'package' => '',
'province' => null,
'province_status' => 0,
'agent' => null,
'agent_status' => 0,
'created_at' => null,
'updated_at' => null,
];
@ -184,7 +187,6 @@ class PropertyService extends Service
return $item->company_id . '_' . $item->package_id;
})->toArray();
$actives = app(OrderCardPartitionRepository::class)->selectRaw('company_id, package_id, count(*) as counts')
->withConditions(['type' => 0, 'card_status' => 2])->groupBy(['company_id', 'package_id'])->get()->keyBy(function ($item) {
return $item->company_id . '_' . $item->package_id;
@ -223,14 +225,15 @@ class PropertyService extends Service
$values = [$values];
}
$only = ['company_id', 'package_id', 'product', 'vehicle', 'commercial_vehicle', 'company', 'platform', 'customer', 'province'];
$only = ['company_id', 'package_id', 'product', 'vehicle', 'commercial_vehicle', 'company', 'platform', 'customer', 'province', 'agent'];
$checks = ['product', 'vehicle', 'company', 'customer'];
$settings = $this->propertySettingRepository->getAll();
$agents = app(AgentService::class)->listGroupByCompanyId();
$data = [];
foreach ($values as $key => $value) {
foreach ($values as $value) {
if (!isset($value['company_id']) || !isset($value['package_id'])) {
continue;
}
@ -265,6 +268,33 @@ class PropertyService extends Service
$value['province'] = json_encode($value['province'], 256);
}
if (!is_null($value['agent'])) {
$itemAgents = $agents[$value['company_id']];
$index = [];
foreach ($value['agent'] as $agent) {
if (in_array($agent['company_id'] . '_' . $agent['platform'], $index)) {
throw new InvalidArgumentException('代理商平台重复配置');
} else {
array_push($index, $agent['company_id'] . '_' . $agent['platform']);
}
if (!in_array($agent['agent'], array_pluck($itemAgents, 'id'))) {
throw new InvalidArgumentException('代理商配置不正确');
}
if (!in_array($agent['platform'], array_keys($settings['platform']))) {
throw new InvalidArgumentException('代理商平台配置不正确');
}
}
if (array_sum(array_pluck($value['agent'], 'percentages')) != 0 && sprintf("%.2f", array_sum(array_pluck($value['agent'], 'percentages'))) != 100) {
throw new InvalidArgumentException('代理商百分比配置不正确');
}
$value['agent'] = json_encode($value['agent'], 256);
}
if (!$package = $this->getPackage($value['product'])) {
throw new NotExistException('产品套餐关系未配置');
}
@ -281,7 +311,9 @@ class PropertyService extends Service
throw new NotAllowedException('数据未修改');
}
$this->propertyRepository->upsert(array_values($data), ['company_id', 'package_id']);
$values = array_values($data);
$this->propertyRepository->upsert($values, ['company_id', 'package_id']);
$this->propertyRepository->forgetCached();

View File

@ -10,6 +10,7 @@ class Property extends Model
protected $casts = [
'province' => 'array',
'agent' => 'array',
];
public function company()

View File

@ -25,7 +25,7 @@ class CreatePropertyTables extends Migration
$table->string('platform', 100)->default('')->comment('平台/API类型');
$table->string('customer', 100)->default('')->comment('客户类型');
$table->string('package', 100)->default('')->comment('套餐分类');
$table->text('province', 100)->nullable()->comment('省份设置');
$table->text('province')->nullable()->comment('省份设置');
$table->timestamps();
$table->unique(['company_id', 'package_id']);
@ -37,7 +37,7 @@ class CreatePropertyTables extends Migration
if (!Schema::hasTable('virtual_property_settings')) {
Schema::create('virtual_property_settings', function (Blueprint $table) {
$table->string('name', 20)->default('');
$table->text('value', 100)->nullable();
$table->text('value')->nullable();
$table->primary('name');
$table->comment('卡属性分类配置');

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddVirtualPropertiesAgent extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('virtual_properties', function (Blueprint $table) {
$table->text('agent')->nullable()->comment('代理商设置');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('virtual_properties', function (Blueprint $table) {
$table->dropColumn('agent');
});
}
}

View File

@ -12,7 +12,7 @@ class PropertySettingSeeder extends Seeder
'customer' => ['行业客户','车后市场客户'],
'package' => ['A类套餐'=>['行车记录仪','电子狗'],'B类套餐'=>['智能后视镜'],'C类套餐'=>['物联网终端','北斗/GPS定位器','北斗超长待机终端','车载WIFI'],'D类套餐'=>['北斗/4G部标机']],
'package_type' => ['A类套餐','B类套餐','C类套餐','D类套餐'],
'platform' => ['TSP平台','API接口','车控宝平台'],
'platform' => ['TSP平台','API接口','主动安全防控平台', '塔杆北斗应急监控平台', '网约车/出租车监控平台', '金融租赁风控平台', '公务车监管平台', '政府监管平台', '电动摩托车监控平台'],
'product' => ['物联网终端','北斗/GPS定位器','电子狗','行车记录仪','后视镜','大屏机','北斗/4G部标机','智能后视镜','北斗超长待机终端','车载WIFI'],
'province' => ['福建省','广东省','山东省','江西省','安徽省','湖北省','江苏省','浙江省','上海市','四川省','河北省','湖南省','广西壮族自治区','山西省','辽宁省','河南省','贵州省','云南省','北京市','青海省','新疆维吾尔自治区','重庆市','天津市','吉林省','黑龙江省','海南省','陕西省','甘肃省','内蒙古自治区','西藏自治区','宁夏回族自治区','台湾省','香港特别行政区','澳门特别行政区'],
'vehicle' => ['乘用车','商用车','其他'],

View File

@ -13,6 +13,17 @@ export function settings(data) {
});
}
/**
* [agents 代理商设置]
* @param {[type]} data [description]
* @return {[type]} [description]
*/
export function agents(data) {
return service.get('api/virtual/properties/agents', {
params: data
});
}
/**
* [settingsStore 属性设置存储]
* @param {[type]} data [description]

View File

@ -0,0 +1,24 @@
<template>
<Drawer
:mask-closable="false"
@on-visible-change="visibleChange"
title="代理商设置"
v-model="my_show"
width="900"
>
<div class="page-edit-wrap uinn-lr20">
<Row class="umar-b20" v-if="isUpdate">
<Button @click="add" icon="md-add" class="f-r" type="primary">添加</Button>
</Row>
<Table :columns="columns" :data="dataAgent"></Table>
</div>
<div class="ta-c">
<Button @click="clear" class="w-80 umar-r5" ghost type="primary">取消</Button>
<Button v-if="isUpdate" :loading="loading" @click="ok" class="w-80" type="primary">确认</Button>
</div>
</Drawer>
</template>
<script src="./js/agent.js"></script>

View File

@ -123,6 +123,15 @@
@province-success="handleProvinceSuccess"
></ui-edit>
<ui-agent
:data="agentObj.data"
:isUpdate="agentObj.isUpdate"
:show.sync="agentObj.show"
:agents="agentsProp ? agentsProp : []"
:platforms="settingsData.platform ? settingsData.platform : []"
@agent-success="handleAgentSuccess"
></ui-agent>
<ui-settings :data="settingsData" :show.sync="settingsShow" @store-success="updateSettings"></ui-settings>
</div>
</template>

View File

@ -0,0 +1,195 @@
export default {
props: {
show: {
type: Boolean,
default: false
},
data: {
type: Object,
default() {
return null;
}
},
isUpdate: {
type: Boolean,
default() {
return false;
}
},
agents: {
type: Array,
default() {
return [];
}
},
platforms: {
type: Array,
default() {
return [];
}
}
},
data() {
return {
my_show: false,
loading: false,
dataAgent: [],
columns: [
{
title: '代理商',
key: 'agent',
minWidth: 180,
render: (h, context) => {
let options = [];
for (let index = 0; index < this.agents.length; index++) {
const element = this.agents[index];
options.push(h('Option', {
props: {
label: element.name,
value: element.id
}
}, element.name));
}
return h('Select', {
props: {
disabled: !this.isUpdate,
value: context.row.agent,
size: 'small',
transfer: true
},
on: {
input: (val) => {
context.row.agent = val;
this.dataAgent[context.index]['agent'] = val;
}
}
}, options);
}
},
{
title: '平台/API',
key: 'platform',
minWidth: 180,
render: (h, context) => {
let options = [];
for (let index = 0; index < this.platforms.length; index++) {
const element = this.platforms[index];
options.push(h('Option', {
props: {
label: element,
value: index
}
}, element));
}
return h('Select', {
props: {
disabled: !this.isUpdate,
value: context.row.platform,
size: 'small',
transfer: true
},
on: {
input: (val) => {
context.row.platform = val;
this.dataAgent[context.index]['platform'] = val;
}
}
}, options);
}
},
{
title: '占比',
minWidth: 120,
render: (h, context) => {
return h('InputNumber', {
props: {
max: 100,
min: 0,
value: context.row.percentages,
disabled: !this.isUpdate
},
on: {
'on-change': (val) => {
context.row.percentages = val;
this.dataAgent[context.index]['percentages'] = val;
}
}
});
}
}
]
};
},
watch: {
show(bool) {
this.my_show = bool;
if (bool) {
if (this.data) {
this.dataAgent = this.data.agent ? this.data.agent : [];
}
}
}
},
methods: {
ok() {
let total = this.dataAgent.reduce((acc, cur) => {
return acc + cur.percentages;
}, 0);
if (total !== 100) {
return this.$Message.error('占比总和必须为100');
}
let agent = [];
for (const key in this.dataAgent) {
const element = this.dataAgent[key];
if (element.agent === undefined) {
return this.$Message.error('请选择代理商');
}
if (element.platform === undefined) {
return this.$Message.error('请选择平台');
}
if (element.percentages < 0 || element.percentages > 100) {
return this.$Message.error('百分比填写不正确');
}
agent.push(element);
}
let data = JSON.parse(JSON.stringify(this.data));
data.agent = agent;
console.log('agent-success', data);
this.$emit('agent-success', data);
this.clear();
},
visibleChange(bool) {
if (!bool) {
this.$emit('update:show', false);
}
},
clear() {
this.dataAgent = [];
this.my_show = false;
},
add() {
if (!this.agents.length) {
return this.$Message.error('请先添加代理商');
}
if (!this.platforms.length) {
return this.$Message.error('请先添加平台配置');
}
this.dataAgent.push({ percentages: 0 });
}
}
};

View File

@ -4,6 +4,7 @@ export default {
name: 'Products',
components: {
UiEdit: resolve => require(['views/virtual/properties/edit'], resolve),
UiAgent: resolve => require(['views/virtual/properties/agent'], resolve),
UiSettings: resolve => require(['views/virtual/properties/settings'], resolve)
},
data() {
@ -14,16 +15,23 @@ export default {
company_id: '',
package_id: ''
},
only: ['company_id', 'package_id', 'product', 'vehicle', 'commercial_vehicle', 'company', 'platform', 'customer', 'province'],
only: ['company_id', 'package_id', 'product', 'vehicle', 'commercial_vehicle', 'company', 'platform', 'customer', 'province', 'agent'],
updates: [],
settingsShow: false,
settingsData: {},
agentsData: {},
agentsProp: [],
editModel: false,
editObj: {
show: false,
isUpdate: false,
data: null
},
agentObj: {
show: false,
isUpdate: false,
data: null
},
search: {
show: true
},
@ -160,6 +168,44 @@ export default {
}, [button]));
}
if (html.length) {
return h('div', html);
}
}
},
{
title: '代理商',
key: 'action',
width: 150,
render: (h, {
row,
column,
index
}) => {
let html = [];
if (this.haveJurisdiction('update')) {
let button = h('Button', {
props: {
type: row.agent ? 'success' : 'error',
size: 'small'
},
class: ['btn'],
on: {
click: (event) => {
this.agentObj = { show: true, data: row, isUpdate: this.editModel };
this.agentsProp = this.agentsData[row.company_id] ? this.agentsData[row.company_id] : [];
}
}
}, this.editModel ? '设置' : '查看');
html.push(h('Tooltip', {
props: {
content: row.agent ? '已设置' : '代理商未设置'
}
}, [button]));
}
if (html.length) {
return h('div', html);
}
@ -195,6 +241,7 @@ export default {
created() {
this.index();
this.settings();
this.agents();
},
methods: {
editRender(key, h, context) {
@ -218,7 +265,8 @@ export default {
return h('Select', {
props: {
value: context.row[key],
size: 'small'
size: 'small',
transfer: true
},
on: {
input: (value) => {
@ -253,7 +301,7 @@ export default {
complete() {
let companies = {};
this.properties.map(function(item) {
this.properties.map(function (item) {
companies[item.company_id] = item.company_name;
});
@ -267,7 +315,7 @@ export default {
let packages = {};
this.properties.map(function(item) {
this.properties.map(function (item) {
packages[item.package_id] = item.package_name;
});
@ -322,6 +370,15 @@ export default {
this.showData = properties.slice((page - 1) * this.page.limit, page * this.page.limit);
},
agents() {
if (!this.agentsData.length) {
API.agents().then(res => {
if (res.code === 0) {
this.agentsData = res.data;
}
});
}
},
settings() {
if (!this.settingsData.length) {
API.settings().then(res => {
@ -334,7 +391,6 @@ export default {
updateSettings(values) {
this.settingsData = values;
},
ok() {
if (!this.updates.length) {
this.$Message.warning('数据未修改');
@ -371,6 +427,12 @@ export default {
this.changePage(this.page.page);
this.updates[index] = this.properties[index];
},
handleAgentSuccess(data) {
let index = (this.page.page - 1) * this.page.limit + data._index;
this.properties[index] = data;
this.changePage(this.page.page);
this.updates[index] = this.properties[index];
},
exportExcel() {
let params = {};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-1a1a22d5.6166dab5.css rel=prefetch><link href=/css/chunk-42b3944b.68383367.css rel=prefetch><link href=/js/chunk-1a1a22d5.09fd5492.js rel=prefetch><link href=/js/chunk-29ecfeab.2fbfdf81.js rel=prefetch><link href=/js/chunk-42b3944b.3545e247.js rel=prefetch><link href=/js/chunk-5b684432.422b14b3.js rel=prefetch><link href=/css/app.42353d5a.css rel=preload as=style><link href=/css/chunk-vendors.a38c182d.css rel=preload as=style><link href=/js/app.72985b05.js rel=preload as=script><link href=/js/chunk-vendors.a5156fe1.js rel=preload as=script><link href=/css/chunk-vendors.a38c182d.css rel=stylesheet><link href=/css/app.42353d5a.css rel=stylesheet></head><body><noscript><strong>很抱歉如果没有启用JavaScript程序不能正常工作若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.a5156fe1.js></script><script src=/js/app.72985b05.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-1a1a22d5.6166dab5.css rel=prefetch><link href=/css/chunk-78a73e84.2e3b3a70.css rel=prefetch><link href=/js/chunk-1a1a22d5.09fd5492.js rel=prefetch><link href=/js/chunk-29ecfeab.2fbfdf81.js rel=prefetch><link href=/js/chunk-5b684432.422b14b3.js rel=prefetch><link href=/js/chunk-78a73e84.e980c7ec.js rel=prefetch><link href=/css/app.42353d5a.css rel=preload as=style><link href=/css/chunk-vendors.a38c182d.css rel=preload as=style><link href=/js/app.ac45104f.js rel=preload as=script><link href=/js/chunk-vendors.a5156fe1.js rel=preload as=script><link href=/css/chunk-vendors.a38c182d.css rel=stylesheet><link href=/css/app.42353d5a.css rel=stylesheet></head><body><noscript><strong>很抱歉如果没有启用JavaScript程序不能正常工作若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.a5156fe1.js></script><script src=/js/app.ac45104f.js></script></body></html>