Commit 7bb8c283 by 杨树贤

对接子账号操作账号

parent adbf7650
......@@ -125,6 +125,7 @@ RABBITMQ2_QUEUE=wms_service
ES_SKU_URL=http://so.liexin.net/search/Es/searchSku
ES_URL=http://so.liexin.net
CLOUD_URL=http://cloud.liexindev.net
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
......@@ -146,4 +147,4 @@ MENU_ID=16
MENU_URL=http://data.liexin.net/api/config/
FOOTSTONE_URL=http://footstone.liexindev.net
#标签系统的地址
TAG_URL=http://192.168.1.18:32581
\ No newline at end of file
TAG_URL=http://192.168.1.18:32581
......@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\Filter\SupplierAccountFilter;
use App\Http\Services\LogService;
use App\Http\Services\SupplierAccountService;
use App\Http\Services\SupplierSubAccountService;
use App\Http\Transformers\SupplierLogTransformer;
use App\Http\Validators\SupplierAccountValidator;
use App\Model\LogModel;
......@@ -133,6 +134,7 @@ class SupplierAccountApiController extends Controller
$this->response(-1, '禁用失败', $result);
}
//获取供应商账号
public function GetSupplierAccount($request)
{
$id = $request->input('id');
......@@ -144,4 +146,38 @@ class SupplierAccountApiController extends Controller
$logService->AddLog($account['supplier_id'], LogModel::VIEW_OPERATE, '查看供应商基本资料', $content);
$this->response(0, 'ok', $account);
}
//子账号管理
public function GetSupplierSubAccountList($request)
{
$map = $request->all();
$result = (new SupplierSubAccountService())->getSupplierSubAccountList($map);
$this->response(0, 'ok', $result['list'], $result['total']);
}
//禁用子账号
public function DisableSupplierSubAccount($request)
{
$id = $request->get('id');
$model = new SupplierAccountModel();
$data['update_time'] = date('Y-m-d H:i:s');
$data['a_status'] = 0;
$result = $model->where('id', $id)->update($data);
if ($result) {
$this->response(0, '禁用成功');
}
$this->response(-1, '禁用失败', $result);
}
//删除子账号
public function DeleteSupplierSubAccount($request)
{
$id = $request->get('id');
$model = new SupplierAccountModel();
$result = $model->where('id', $id)->delete();
if ($result) {
$this->response(0, '禁用成功');
}
$this->response(-1, '禁用失败', $result);
}
}
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Http\Services\RoleService;
use App\Http\Services\SupplierAccountService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
use App\Http\Services\ViewCheckService;
......@@ -86,4 +87,26 @@ class SupplierAccountController extends Controller
return $this->view('编辑供应商账号');
}
}
\ No newline at end of file
//子账号列表
public function SupplierSubAccountList($request)
{
$accountId = $request->input('account_id');
if (!$accountId) {
return '账号id不能为空';
}
$supplierId = SupplierAccountModel::where('id', $accountId)->value('supplier_id');
$supplier = (new SupplierService())->getSupplier($supplierId);
$supplierAccount = (new SupplierAccountService())->getSupplierAccountBySupplierId($supplierId);
$this->data['supplier'] = $supplier;
$this->data['supplierAccount'] = $supplierAccount;
$this->data['title'] = '子账号管理';
return $this->view('子账号管理');
}
//新增修改子账号
public function SaveSupplierSubAccount($request)
{
$this->data['title'] = '子账号编辑';
return $this->view('子账号编辑');
}
}
......@@ -6,7 +6,9 @@ namespace App\Http\Services;
use App\Http\Controllers\Filter\SupplierAccountFilter;
use App\Http\Transformers\SupplierAccountTransformer;
use App\Http\Transformers\SupplierTransformer;
use App\Model\LogModel;
use App\Model\SupplierAccountModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use Carbon\Carbon;
......@@ -48,4 +50,12 @@ class SupplierAccountService
$channel->close();
$conn->close();
}
}
\ No newline at end of file
//获取单个账号的信息
public function getSupplierAccountBySupplierId($supplierId)
{
$supplierAccount = SupplierAccountModel::where('supplier_id', $supplierId)->first()->toArray();
$supplierAccount = (new SupplierAccountTransformer())->transformInfo($supplierAccount);
return $supplierAccount;
}
}
<?php
namespace App\Http\Services;
use App\Http\Controllers\Filter\SupplierAccountFilter;
use App\Http\Transformers\SupplierAccountTransformer;
use App\Http\Transformers\SupplierTransformer;
use App\Model\LogModel;
use App\Model\SupplierAccountModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use Carbon\Carbon;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
class SupplierSubAccountService
{
public function __construct()
{
}
public function generateRequestAuthData($accountId)
{
$supplierAccount = SupplierAccountModel::where('id', $accountId)->first()->toArray();
return [
'source_create_type' => 2,
'password' => $supplierAccount['password'],
'id' => $accountId,
];
}
public function getSupplierSubAccountList($map)
{
$url = config('website.CloudUrl') . '/inner/subAccount/list';
$params = $this->generateRequestAuthData($map['account_id']);
$params = array_merge($map, $params);
unset($params['account_id']);
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
return $result['data'];
}
return [];
}
//新增子账号
public function addSupplierSubAccount($accountId, $data)
{
$url = config('website.CloudUrl') . '/inner/subAccount/create';
$params = $this->generateRequestAuthData($accountId);
$params = array_merge($data, $params);
$result = json_decode(curl($url, $params, true), true);
if (isset($result['code']) && $result['code'] == 0) {
return true;
}
return false;
}
public function updateSupplierSubAccount($accountId,$data)
{
$url = config('website.CloudUrl') . '/inner/subAccount/edit';
$params = $this->generateRequestAuthData($accountId);
$params = array_merge($data, $params);
$result = json_decode(curl($url, $params, true), true);
if (isset($result['code']) && $result['code'] == 0) {
return true;
}
return false;
}
//获取用户的权限菜单
public function getSupplierAccountPermList($accountId)
{
$url = config('website.CloudUrl') . '/inner/subAccount/getMenu';
$params = $this->generateRequestAuthData($accountId);
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
return $result['data'];
}
return [];
}
//修改子账号状态
//1启动2禁用0删除
public function changeSupplierSubAccountStatus($accountId, $status)
{
$url = config('website.CloudUrl') . '/inner/subAccount/changeStatus';
$params = $this->generateRequestAuthData($accountId);
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
return true;
}
return false;
}
}
......@@ -16,18 +16,36 @@ class SupplierAccountTransformer
$suppliers = $supplierModel->whereIn('supplier_id', $supplierIds)->pluck('supplier_name', 'supplier_id');
foreach ($list as &$item) {
$item['supplier_name'] = array_get($suppliers, $item['supplier_id']);
$item['type_name'] = array_get(config('field.SupplierAccountType'), $item['a_type']);
$item['create_time'] = $item['create_time'] ? date('Y-m-d H:i:s', $item['create_time']) : '';
$item['update_time'] = $item['update_time'] ? date('Y-m-d H:i:s', $item['update_time']) : '';
if (!empty($item['mobile'])) {
$item['mobile'] = substr($item['mobile'], 0, 3) . '****' . substr($item['mobile'], 7);
}
$replace = str_pad('*', strlen($item['password_raw']), '*');
$item['password_raw'] = str_replace($item['password_raw'], $replace , $item['password_raw']);
$item = $this->transformInfo($item);
}
unset($item);
return $list;
}
}
\ No newline at end of file
public function transformInfo($item)
{
$item['type_name'] = array_get(config('field.SupplierAccountType'), $item['a_type']);
$item['create_time'] = $item['create_time'] ? date('Y-m-d H:i:s', $item['create_time']) : '';
$item['update_time'] = $item['update_time'] ? date('Y-m-d H:i:s', $item['update_time']) : '';
if (!empty($item['mobile'])) {
$item['mobile'] = substr($item['mobile'], 0, 3) . '****' . substr($item['mobile'], 7);
}
if (!empty($item['email'])) {
$emailTemp = explode('@', $item['email'])[0];
$replace = str_pad('*', strlen($emailTemp), '*');
$emailTemp = str_replace($emailTemp, $replace, $emailTemp);
if (count(explode('@', $item['email'])) > 1) {
$item['email'] = $emailTemp . '@' . explode('@', $item['email'])[1];
} else {
$item['email'] = $emailTemp;
}
}
$replace = str_pad('*', strlen($item['password_raw']), '*');
$item['password_raw'] = str_replace($item['password_raw'], $replace , $item['password_raw']);
return $item;
}
}
......@@ -204,8 +204,9 @@ class SupplierTransformer
array_get($supplier, 'has_certification', ''), '');
$supplier['sku_tag_name'] = array_get(config('field.SkuTag'), array_get($supplier, 'sku_tag', ''), '无');
$supplier['sku_mode_name'] = array_get(config('field.SkuMode'), array_get($supplier, 'sku_mode', ''), '无');
// $supplier['purchase_type'] = array_get(config('field.PurchaseType'), array_get($supplier, 'purchase_type', ''), '无');
$supplier['purchase_type_name'] = array_get(config('field.PurchaseType'), $supplier['purchase_type'], '无');
$supplier['cp_time_format'] = ('现货 : ' . ($supplier['cp_time_day'] == -1 ? '无限制' : $supplier['cp_time_day'] . '天')) . ' | '
. ('期货 : ' . ($supplier['futures_cp_time_day'] == -1 ? '无限制' : $supplier['futures_cp_time_day'] . '天'));
return $supplier;
}
......@@ -364,4 +365,4 @@ class SupplierTransformer
return $supplier;
}
}
\ No newline at end of file
}
......@@ -40,4 +40,6 @@ return [
'templet' => 'http://footstone.liexin.net/footstone/templet?', // 专卖商品批量导出
],
'TagUrl' => env('TAG_URL'),
'CloudUrl' => env('CLOUD_URL'),
];
<script>
layui.use(['table', 'form', 'tree', 'element', 'table', 'layer', 'admin', 'xmSelect'], function () {
let admin = layui.admin;
let form = layui.form;
let tree = layui.tree;
form.on('submit(saveSupplierSubAccount)', function (data) {
let url = '/api/supplier_account/SaveSupplierSubAccount';
let res = ajax(url, data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
parent.layer.msg(res.err_msg, {icon: 5});
}
}
return false;
});
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
// 渲染树形组件
tree.render({
elem: '#permTree',
data: [
{
title: '节点1',
children: [
{title: '子节点1'},
{title: '子节点2'}
]
},
{
title: '节点2',
children: [
{title: '子节点3'},
{title: '子节点4'}
]
}
],
click: function (obj) {
console.log(obj.data); // 点击事件回调函数
}
});
});
</script>
<script>
layui.use(['table', 'form', 'element', 'layer', 'Split', 'admin', 'xmSelect'], function () {
let $ = layui.jquery;
let table = layui.table;
let form = layui.form;
let admin = layui.admin;
let initCondition = {};
let whereCondition = initCondition;
whereCondition.account_id = getQueryVariable('account_id');
let cols = [
{
field: 'mobile', title: '子账号', align: 'center', width: 170,
templet: function (data) {
return '<span>' + data.mobile + '</span><span style="color: dodgerblue;margin-left: 10px" class="viewAccount" type="mobile" id="' + data.id + '">查看</span>'
}
},
{
field: 'password_raw', title: '密码', align: 'center', width: 170,
templet: function (data) {
return '<span>' + data.password_raw + '</span><span style="color: dodgerblue;margin-left: 10px" class="viewAccount" type="password_raw" id="' + data.id + '">查看</span>'
}
},
{field: 'create_type_cn', title: '创建人', align: 'center', width: 150},
{field: 'create_time_cn', title: '创建时间', align: 'center', width: 150},
{field: 'update_time_cn', title: '修改时间', align: 'center', width: 150},
];
let currentPage = 0;
table.render({
elem: '#supplierSubAccountList'
, url: '/api/supplier_account/GetSupplierSubAccountList'
, method: 'post'
, size: 'sm'
, limit: 20
, cellMinWidth: 50 //全局定义常规单元格的最小宽度
, where: whereCondition
, loading: true
, first: true //不显示首页
, last: false //不显示尾页
, cols: [cols]
, id: 'supplierSubAccountList'
, page: {}
, done: function (res, curr, count) {
currentPage = curr;
}
});
//启用
$("#enable_supplier_sub_account").click(function () {
let checkStatus = table.checkStatus('supplierSubAccountList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的供应商账号', {icon: 5})
} else {
layer.confirm('确定要启用该供应商账号吗?', function (index) {
let id = data[0].id;
let res = ajax('/api/supplier_account/EnableSupplierSubAccount', {id: id})
if (res.err_code === 0) {
table.reload('supplierSubAccountList');
layer.closeAll();
layer.msg(res.err_msg, {icon: 6})
} else {
layer.msg(res.err_msg, {icon: 5})
}
});
}
});
//禁用
$("#disable_supplier_sub_account").click(function () {
let checkStatus = table.checkStatus('supplierSubAccountList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的供应商账号', {icon: 5})
} else {
layer.confirm('确定要禁用该供应商账号吗?', function (index) {
let id = data[0].id;
let res = ajax('/api/supplier_account/DisableSupplierSubAccount', {id: id})
if (res.err_code === 0) {
table.reload('supplierSubAccountList');
layer.closeAll();
layer.msg(res.err_msg, {icon: 6})
} else {
layer.msg(res.err_msg, {icon: 5})
}
});
}
});
//根据供应商编码已经品牌等去基石调用接口下架
$("#add_supplier_sub_account").click(function () {
layer.open({
type: 2,
content: '/supplier_sub_account/AddSupplierSubAccount?view=iframe',
area: ['800px', '600px'],
title: '添加供应商账号',
end: function () {
table.reload('supplierSubAccountList');
// supplierStatistics();
}
});
});
$("#update_supplier_sub_account").click(function () {
let checkStatus = table.checkStatus('supplierSubAccountList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的供应商', {icon: 5})
} else {
let id = data[0].id;
layer.open({
type: 2,
content: '/supplier_sub_account/UpdateSupplierSubAccount?view=iframe&id=' + id,
area: ['800px', '600px'],
title: '批量下架SKU',
end: function () {
table.reload('supplierSubAccountList');
// supplierStatistics();
}
});
}
});
form.on('submit(load)', function (data) {
whereCondition = $.extend(false, initCondition, data.field);
//执行重载
table.reload('supplierSubAccountList', {
page: {
curr: 1
}
, where: whereCondition
});
return false;
});
form.on('submit(reset)', function (data) {
layer.load(1);
location.reload();
});
$(document).on('click', '.viewAccount', function () {
if ($(this).text() === '隐藏') {
$(this).prev().text($(this).attr('prev_text'));
$(this).text('查看');
} else {
let id = $(this).attr('id');
let type = $(this).attr('type');
let resp = ajax('/api/supplier_account/GetSupplierSubAccount', {id: id, type: type});
if (!resp) {
layer.msg('网络连接失败', {'icon': 5});
return false;
}
let prevText = $(this).prev().text();
$(this).attr('prev_text', prevText);
if (resp.err_code === 0) {
switch (type) {
case 'mobile':
$(this).prev().text(resp.data.mobile);
break;
case 'password_raw':
$(this).prev().text(resp.data.password_raw);
break;
}
console.log(resp);
$.get(getLogDomain() + "/api/addSensitiveClick", {
uid: getCookie("oa_user_id") || 0,
sys_id: 4,
mask_type: type || 0,
origin_id: id || 0,
source_from: window.location.href
});
$(this).text('隐藏');
} else {
layer.msg(resp.err_msg, {'icon': 5});
return false;
}
}
});
});
</script>
<style>
.layui-form-item {
margin-bottom: 5px;
}
.layui-tree .layui-tree-set {
display: inline-block;
margin-right: 10px; /* 控制节点之间的水平间距 */
vertical-align: top; /* 将节点对齐到顶部 */
}
</style>
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form" action="">
<blockquote class="layui-elem-quote layui-text">
<b>子账号信息</b>
</blockquote>
<div class="layui-row">
<div class="layui-col-md3">
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>账号 : </label>
<div class="layui-input-block">
<input type="text" name="mobile" id="mobile"
placeholder="请输入登录账号" class="layui-input"
value="{{$account['mobile'] or ''}}">
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>密码 : </label>
<div class="layui-input-block">
<input type="text" name="mobile" id="mobile"
placeholder="请输入登录账号" class="layui-input"
value="{{$account['mobile'] or ''}}">
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>名称 : </label>
<div class="layui-input-block">
<input type="text" name="mobile" id="mobile"
placeholder="请输入登录账号" class="layui-input"
value="{{$account['mobile'] or ''}}">
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>邮箱 : </label>
<div class="layui-input-block">
<input type="text" name="mobile" id="mobile"
placeholder="请输入登录账号" class="layui-input"
value="{{$account['mobile'] or ''}}">
</div>
</div>
</div>
</div>
<blockquote class="layui-elem-quote layui-text">
<span><b>子账号权限配置</b> <span style="margin-left: 10px;"> <i class="layui-icon layui-icon-note"
style="color: orange;font-size: 16px"></i> 勾选以下页面后,子账号可以看到对应的页面内容并进行操作;没有勾选的页面,子账号则无权查看;</span> </span>
</blockquote>
<div class="layui-form-item">
<div id="permTree"></div>
</div>
<blockquote class="layui-elem-quote layui-text">
<b>子账号消息推送配置</b>
</blockquote>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>账号类型 : </label>
<div class="layui-input-block">
<input type="checkbox" name="a_type" title="芯链商家" lay-skin="primary" checked>
</div>
</div>
<div class="layui-form-item">
<div align="center" style="margin-top: 20px;text-align: right">
<button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
lay-filter="addSupplierAccount">确定
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
lay-filter="cancel">取消
</button>
</div>
</div>
</form>
</div>
</div>
<blockquote class="layui-elem-quote layui-text">
<b>供应商信息</b>
</blockquote>
<table class="layui-table">
<colgroup>
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>供应商编码</th>
<th>供应商名称</th>
<th>供应商性质</th>
<th>有效期最高天数</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{$supplier['supplier_code']}}</td>
<td>{{$supplier['supplier_name']}}</td>
<td>{{$supplier['supplier_group_name']}}</td>
<td>{{$supplier['cp_time_format']}}</td>
</tr>
</tbody>
</table>
<br>
<blockquote class="layui-elem-quote layui-text">
<b>芯链主账号信息</b>
</blockquote>
<table class="layui-table">
<colgroup>
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>联系人</th>
<th>联系电话</th>
<th>邮箱</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{$supplierAccount['contacts_name']}}</td>
<td>{{$supplierAccount['mobile']}}</td>
<td>{{$supplierAccount['email']}}</td>
<td>{{$supplierAccount['create_time']}}</td>
<td>
<button class="layui-btn layui-btn-sm">详情</button>
</td>
</tr>
</tbody>
</table>
<br>
<blockquote class="layui-elem-quote layui-text">
<b>芯链子账号信息</b>
</blockquote>
<div style="margin-left: 20px;margin-right: 20px">
<div class="layui-btn-group demoTable" style="margin-top: 15px">
<button type="button" class="layui-btn layui-btn-sm" id="add_supplier_sub_account">创建子账号</button>
</div>
<table class="layui-table" id="supplierSubAccountList" lay-filter="supplierSubAccountList"></table>
</div>
<script>
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment