Commit be171628 by 杨树贤

保存子账号页面

parent 7bb8c283
......@@ -17,6 +17,7 @@ use App\Model\SupplierLogModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Validator;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
......@@ -155,6 +156,55 @@ class SupplierAccountApiController extends Controller
$this->response(0, 'ok', $result['list'], $result['total']);
}
public function SaveSupplierSubAccount($request)
{
$data = $request->only([
'account_id',
'sbat_id',
'mobile',
'password_raw',
'name',
'email',
'user_rule',
'user_message_rule',
]);
$rules = [
"mobile" => "required|regex:/^1[0-9][0-9]{9}$/",
"password_raw" => "required",
"name" => "required",
"email" => "required|email",
];
$messages = [
'supplier_code.required' => '请选择一个供应商',
'mobile.required' => '登录账号不能为空',
'mobile.regex' => '账号格式必须为手机号',
'email.email' => '邮箱格式不对',
'password_raw.required' => '账号密码不能为空',
];
$validator = Validator::make($data, $rules, $messages);
//判断联系方式的表单验证
if ($validator->fails()) {
$this->response(-1, $validator->errors()->first());
}
$data['user_rule'] = $data['user_rule']?:[];
$data['user_rule'] = json_encode($data['user_rule']);
$data['user_message_rule'] = $data['user_message_rule']?:[];
$data['user_message_rule'] = json_encode($data['user_message_rule']);
$accountId = $data['account_id'];
unset($data['account_id']);
if (empty($data['sbat_id'])) {
unset($data['sbat_id']);
$result = (new SupplierSubAccountService())->addSupplierSubAccount($accountId, $data);
} else {
$result = (new SupplierSubAccountService())->addSupplierSubAccount($accountId, $data);
}
if ($result === true) {
$this->response(0, '操作成功');
} else {
$this->response(-1, $result);
}
}
//禁用子账号
public function DisableSupplierSubAccount($request)
{
......
......@@ -6,6 +6,7 @@ use App\Http\Services\RoleService;
use App\Http\Services\SupplierAccountService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierSubAccountService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\SupplierAccountModel;
......@@ -106,6 +107,18 @@ class SupplierAccountController extends Controller
//新增修改子账号
public function SaveSupplierSubAccount($request)
{
$accountId = $request->input('account_id');
$sbatId = $request->input('sbat_id');
$ynatId = $request->input('ynat_id');
if (!empty($sbatId)) {
$account = (new SupplierSubAccountService())->getSupplierSubAccount($accountId, $sbatId);
$this->data['account'] = $account;
}
$menuPerms = (new SupplierSubAccountService())->getSupplierAccountPermList($accountId, $sbatId);
$messagePerms = (new SupplierSubAccountService())->getSupplierAccountMessagePermList($accountId, $ynatId);
// dd($menuPerms);
$this->data['menuPerms'] = $menuPerms;
$this->data['messagePerms'] = $messagePerms;
$this->data['title'] = '子账号编辑';
return $this->view('子账号编辑');
}
......
......@@ -18,11 +18,6 @@ use PhpAmqpLib\Message\AMQPMessage;
class SupplierSubAccountService
{
public function __construct()
{
}
public function generateRequestAuthData($accountId)
{
$supplierAccount = SupplierAccountModel::where('id', $accountId)->first()->toArray();
......@@ -33,6 +28,20 @@ class SupplierSubAccountService
];
}
public function getSupplierSubAccount($accountId, $sbatId)
{
$url = config('website.CloudUrl') . '/inner/subAccount/getSubAccountInfo';
$params = $this->generateRequestAuthData($accountId);
$params['sbat_id'] = $sbatId;
unset($params['account_id']);
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
return $result['data'];
}
return [];
}
public function getSupplierSubAccountList($map)
{
$url = config('website.CloudUrl') . '/inner/subAccount/list';
......@@ -55,11 +64,12 @@ class SupplierSubAccountService
$result = json_decode(curl($url, $params, true), true);
if (isset($result['code']) && $result['code'] == 0) {
return true;
} else {
return $result['msg'];
}
return false;
}
public function updateSupplierSubAccount($accountId,$data)
public function updateSupplierSubAccount($accountId, $data)
{
$url = config('website.CloudUrl') . '/inner/subAccount/edit';
$params = $this->generateRequestAuthData($accountId);
......@@ -67,19 +77,81 @@ class SupplierSubAccountService
$result = json_decode(curl($url, $params, true), true);
if (isset($result['code']) && $result['code'] == 0) {
return true;
} else {
return $result['msg'];
}
return false;
}
//获取用户的权限菜单
public function getSupplierAccountPermList($accountId)
public function getSupplierAccountPermList($accountId, $sbatId)
{
$url = config('website.CloudUrl') . '/inner/subAccount/getMenu';
$url = config('website.CloudUrl') . '/inner/subAccount/getMenu';
$params = $this->generateRequestAuthData($accountId);
if ($sbatId) {
$params['sbat_id'] = $sbatId;
}else{
$params['method'] = 'add';
}
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
return $result['data'];
$permList = $result['data']['data'];
//还要转换成layui能用的格式
$list = [];
foreach ($permList as $perm) {
$list[] = [
'title' => $perm['name'],
'id' => !empty($perm['path']) ? $perm['path'] : '',
'checked' => $perm['checked'],
'spread' => true,
'children' => !empty($perm['children']) ? $this->getChildPermList($perm['children']) : [],
];
}
return $list;
}
return [];
}
public function getChildPermList($perm)
{
if (empty($perm)) {
return [];
}
$childPermList = [];
foreach ($perm as $item) {
$childPermList[] = [
'title' => $item['name'],
'id' => !empty($item['path']) ? $item['path'] : '',
'checked' => $item['checked'],
'spread' => true,
];
}
return $childPermList;
}
public function getSupplierAccountMessagePermList($accountId, $ynatId)
{
$url = config('website.CloudUrl') . '/inner/subAccount/getMessageMenu';
$params = $this->generateRequestAuthData($accountId);
if ($ynatId) {
$params['ynat_id'] = $ynatId;
}
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
$permList = $result['data']['data'];
//还要转换成layui能用的格式
$list = [];
foreach ($permList as $perm) {
$list[] = [
'title' => $perm['name'],
'id' => !empty($perm['path']) ? $perm['path'] : '',
'checked' => $perm['checked'],
'spread' => true,
'children' => !empty($perm['children']) ? $this->getChildPermList($perm['children']) : [],
];
}
return $list;
}
return [];
}
......
......@@ -5,6 +5,16 @@
let tree = layui.tree;
form.on('submit(saveSupplierSubAccount)', function (data) {
let userRule = [];
$('#permTree').find('.layui-form-checked').next('span').each(function (index, item) {
userRule.push($(item).text());
});
let userMessageRule = [];
$('#messagePermTree').find('.layui-form-checked').next('span').each(function (index, item) {
userMessageRule.push($(item).text());
});
data.field.user_rule = userRule;
data.field.user_message_rule = userMessageRule;
let url = '/api/supplier_account/SaveSupplierSubAccount';
let res = ajax(url, data.field);
if (!res) {
......@@ -26,24 +36,22 @@
// 渲染树形组件
tree.render({
elem: '#permTree',
data: [
{
title: '节点1',
children: [
{title: '子节点1'},
{title: '子节点2'}
]
},
{
title: '节点2',
children: [
{title: '子节点3'},
{title: '子节点4'}
]
}
],
id: 'permTree',
showCheckbox: true,
data: {!! json_encode($menuPerms) !!},
click: function (obj) {
tree.reload('permTree');
}
});
// 渲染树形组件
tree.render({
elem: '#messagePermTree',
id: 'messagePermTree',
showCheckbox: true,
data: {!! json_encode($messagePerms) !!},
click: function (obj) {
console.log(obj.data); // 点击事件回调函数
tree.reload('messagePermTree');
}
});
......
......@@ -27,6 +27,12 @@
}
},
{
field: 'manage_sub_account', title: '子账号', align: 'center', width: 110,
templet: function (data) {
return "<a ew-href='/supplier_account/SupplierSubAccountList?view=iframe&account_id=" + data.id + "' class='list-href' ew-title='子账号管理 - " + data.supplier_code + "'>" + "管理" + "</a>"
}
},
{
field: 'supplier_code', title: '供应商编码', align: 'center', width: 120
},
{field: 'supplier_name', title: '供应商名称', align: 'center'},
......@@ -194,4 +200,4 @@
});
});
</script>
\ No newline at end of file
</script>
......@@ -10,15 +10,15 @@
let cols = [
{
field: 'mobile', title: '子账号', align: 'center', width: 170,
field: 'mobile', title: '子账号', align: 'center', width: 300,
templet: function (data) {
return '<span>' + data.mobile + '</span><span style="color: dodgerblue;margin-left: 10px" class="viewAccount" type="mobile" id="' + data.id + '">查看</span>'
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,
field: 'password_raw', title: '密码', align: 'center', width: 300,
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>'
return '<span>' + '**********' + '</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},
......@@ -91,6 +91,19 @@
$("#add_supplier_sub_account").click(function () {
layer.open({
type: 2,
content: '/supplier_account/SaveSupplierSubAccount?view=iframe&account_id='+getQueryVariable('account_id'),
area: ['70%', '80%'],
title: '添加供应商账号',
end: function () {
table.reload('supplierSubAccountList');
// supplierStatistics();
}
});
});
$("#updateSupplierAccountPerm").click(function () {
layer.open({
type: 2,
content: '/supplier_sub_account/AddSupplierSubAccount?view=iframe',
area: ['800px', '600px'],
title: '添加供应商账号',
......
......@@ -18,7 +18,9 @@
<div class="layui-row">
<div class="layui-col-md3">
<div class="layui-form-item">
<input type="hidden" name="sbat_id" value="{{$account['sbat_id'] or ''}}">
<input type="hidden" name="ynat_id" value="{{$account['ynat_id'] or ''}}">
<input type="hidden" name="account_id" value="{{request()->input('account_id')}}">
<label class="layui-form-label"><span class="require">*</span>账号 : </label>
<div class="layui-input-block">
<input type="text" name="mobile" id="mobile"
......@@ -32,9 +34,9 @@
<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 ''}}">
<input type="text" name="password_raw" id="password_raw"
placeholder="请输入密码" class="layui-input"
value="{{$account['password_raw'] or ''}}">
</div>
</div>
</div>
......@@ -43,9 +45,9 @@
<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 ''}}">
<input type="text" name="name" id="name"
placeholder="请输入名称" class="layui-input"
value="{{$account['name'] or ''}}">
</div>
</div>
</div>
......@@ -54,9 +56,9 @@
<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 ''}}">
<input type="text" name="email" id="email"
placeholder="请输入邮箱" class="layui-input"
value="{{$account['email'] or ''}}">
</div>
</div>
</div>
......@@ -72,15 +74,12 @@
<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 id="messagePermTree"></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">确定
lay-filter="saveSupplierSubAccount">确定
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
lay-filter="cancel">取消
......
......@@ -5,7 +5,7 @@
<table class="layui-table">
<colgroup>
<col width="150">
<col width="200">
<col width="300">
<col>
</colgroup>
<thead>
......@@ -53,7 +53,7 @@
<td>{{$supplierAccount['email']}}</td>
<td>{{$supplierAccount['create_time']}}</td>
<td>
<button class="layui-btn layui-btn-sm">详情</button>
<button class="layui-btn layui-btn-sm" id="updateSupplierAccountPerm">详情</button>
</td>
</tr>
</tbody>
......
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