Commit 1460ab41 by 杨树贤

附件管理

parent 6a4d28bb
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Transformers\SupplierAttachmentTransformer;
use App\Http\Validators\SupplierAttachmentValidator;
use App\Model\LogModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierAttachmentModel;
use Illuminate\Http\Request;
class SupplierAttachmentApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
//获取供应商收款信息
public function GetSupplierAttachmentList($request)
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new SupplierAttachmentModel();
$model->where('supplier_id', $supplierId)->paginate();
$attachmentData = $model->where('supplier_id', $supplierId)->orderBy('id', 'desc')
->first();
$transformer = new SupplierAttachmentTransformer();
$list = $transformer->transformList($attachmentData);
$this->response(0, 'ok', $list, count($list));
}
//获取供应商信息变更记录
public function AddSupplierAttachment($request)
{
//先去表单验证
$validator = new SupplierAttachmentValidator();
$validateResult = $validator->checkSave($request);
if ($validateResult) {
$this->response(-1, $validateResult);
}
$attachment = $request->only([
'attachment_id',
'supplier_id',
'attachment_type',
'bank_name',
'bank_adderss',
'account_no',
'account_adderss',
'swift_code',
'certificate',
'account_name',
'remark',
]);
$attachment['account_adderss'] = empty($attachment['account_adderss']) ? ' ' : $attachment['account_adderss'];
if ($attachment['attachment_type'] == 1) {
$attachment['swift_code'] = '';
}
$attachmentId = $request->get('attachment_id');
$supplierId = $request->get('supplier_id');
$model = new SupplierAttachmentModel();
if (!empty($attachmentId)) {
$oldAttachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
$result = $model->where('attachment_id', $attachmentId)->update($attachment);
} else {
$oldAttachment = [];
$attachment['supplier_id'] = $supplierId;
$result = $model->insertGetId($attachment);
$attachmentId = $result;
}
if ($result) {
$newAttachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
//如果修改的只是备注,则不需要转成审核
$needAudit = $this->checkNeedAudit($oldAttachment, $newAttachment);
if ($needAudit || empty($request->get('attachment_id'))) {
$supplierModel = new SupplierChannelModel();
//修改供应商为审核状态
$supplierModel->where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => SupplierChannelModel::STATUS_PENDING,
]);
}
$logService = new LogService();
$content = !empty($attachment['attachment_id']) ? '修改银行信息' : '添加银行信息';
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
}
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
private function checkNeedAudit($oldAttachment, $newAttachment)
{
$notNeedAuditField = [
'remark',
];
$diff = array_diff($oldAttachment, $newAttachment);
unset($diff['update_time']);
$changeField = array_keys($diff);
foreach ($changeField as $filed) {
//只要有一个不存在于不需要审核的字段,就返回需要审核
if (!in_array($filed, $notNeedAuditField)) {
return true;
}
}
return false;
}
//删除
public function DeleteSupplierAttachment($request)
{
$attachmentId = $request->get('attachment_id');
$model = new SupplierAttachmentModel();
$result = $model->where('attachment_id', $attachmentId)->delete();
if ($result) {
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Services\RoleService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierStatisticsService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierAttachmentModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class SupplierAttachmentController extends Controller
{
public function info(Request $request, $id = '')
{
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'user_email' => $request->user->email,
'uri' => '/' . $path,
'id' => $id,
];
return $this->$id($request);
}
}
public function __call($name, $arr)
{
$data['errinfo'] = '访问路径错误';
return view('errors.error', $data);
}
//供应商详情
public function AddSupplierAttachment($request)
{
$this->data['title'] = '添加附件';
return $this->view('添加附件');
}
//供应商详情
public function UpdateSupplierAttachment($request)
{
$receiptId = $request->get('receipt_id');
if (!empty($receiptId)) {
$model = new SupplierAttachmentModel();
$this->data['receipt'] = $model->where('receipt_id', $receiptId)->first()->toArray();
}
$this->data['title'] = '修改附件';
$this->data['view'] = 'AddSupplierAttachment';
return $this->view('修改附件');
}
}
\ No newline at end of file
<?php
namespace App\Http\Transformers;
class SupplierAttachmentTransformer
{
public function transformList($attachmentData)
{
if (empty($attachmentData)) {
return [];
}
$attachmentData = $attachmentData->toArray();
$attachmentList = [];
$fields = [
'business_license',
'billing_information',
'registration_certificate',
'incorporation_certificate',
'certification_notice',
'supplier_survey',
'proxy_certificate',
'quality_assurance_agreement',
'confidentiality_agreement',
'cooperation_agreement',
'other_attachment',
];
foreach ($fields as $field) {
if (isset($attachmentData[$field])) {
$attachmentData[$field] = json_decode($attachmentData[$field], true);
}
if (empty($attachmentData[$field])) {
continue;
}
foreach ($attachmentData[$field] as $attachment) {
$attachmentList[] = $attachment;
}
}
foreach ($attachmentList as &$attachment) {
if (!$attachment) {
continue;
}
$attachment['name'] = array_get(config('fixed.FileNameMapping'), $attachment['name']);
$attachment['create_time'] = isset($attachment['create_time']) ? date('Y-m-d H:i:s',
$attachment['create_time']) : '';
}
unset($attachment);
return $attachmentList;
}
}
\ No newline at end of file
<?php
namespace App\Http\Validators;
use App\Model\SupplierChannelModel;
use Validator;
class SupplierAttachmentValidator
{
//保存相关的验证,别问我为什么不用laravel自带的form-request类
//因为控制器那边已经被之前的人魔改的难用的一比,而且控制器那边还接收了一大堆统一变量
public function checkSave($request)
{
//整理下请求数据
$receipt = $request->all();
$rules = [
"bank_name" => "required",
"bank_adderss" => "required",
"account_no" => "required",
"receipt_type" => 'required',
// "account_name" => "required",
"certificate" => "required",
];
if ($receipt['receipt_type'] == 2) {
$rules["swift_code"] = 'required';
}
$messages = $this->messages();
$validator = Validator::make($receipt, $rules, $messages);
//判断联系方式的表单验证
if ($validator->fails()) {
return $validator->errors()->first();
}
}
private function messages()
{
return [
'receipt_type.required' => '开户名称不能为空',
'bank_name.required' => '类型不能为空',
'bank_adderss.required' => '开户行不能为空',
'swift_code.required' => '电汇号码 Swift Code 不能为空',
'account_no.required' => '银行账号不能为空',
'account_name.required' => '账户名称不能为空',
'certificate.required' => '银行信息凭证不能为空',
];
}
}
\ No newline at end of file
...@@ -17,6 +17,7 @@ Route::group(['middleware' => ['web', 'menu']], function () { ...@@ -17,6 +17,7 @@ Route::group(['middleware' => ['web', 'menu']], function () {
Route::match(['get', 'post'], '/web/{key}', 'WebController@Entrance'); Route::match(['get', 'post'], '/web/{key}', 'WebController@Entrance');
Route::match(['get', 'post'], '/supplier/{key}', 'SupplierController@info'); Route::match(['get', 'post'], '/supplier/{key}', 'SupplierController@info');
Route::match(['get', 'post'], '/supplier_contact/{key}', 'SupplierContactController@info'); Route::match(['get', 'post'], '/supplier_contact/{key}', 'SupplierContactController@info');
Route::match(['get', 'post'], '/supplier_attachment/{key}', 'SupplierAttachmentController@info');
Route::match(['get', 'post'], '/supplier_receipt/{key}', 'SupplierReceiptController@info'); Route::match(['get', 'post'], '/supplier_receipt/{key}', 'SupplierReceiptController@info');
Route::match(['get', 'post'], '/supplier_account/{key}', 'SupplierAccountController@info'); Route::match(['get', 'post'], '/supplier_account/{key}', 'SupplierAccountController@info');
Route::match(['get', 'post'], '/supplier_share_apply/{key}', 'SupplierShareApplyController@Entrance'); Route::match(['get', 'post'], '/supplier_share_apply/{key}', 'SupplierShareApplyController@Entrance');
...@@ -37,6 +38,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -37,6 +38,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/api/log/{key}', 'LogApiController@Entrance'); Route::match(['get', 'post'], '/api/log/{key}', 'LogApiController@Entrance');
Route::match(['get', 'post'], '/api/sku/{key}', 'SkuApiController@Entrance'); Route::match(['get', 'post'], '/api/sku/{key}', 'SkuApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_receipt/{key}', 'SupplierReceiptApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_receipt/{key}', 'SupplierReceiptApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_attachment/{key}', 'SupplierAttachmentApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_sync_log/{key}', 'SupplierSyncLogApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_sync_log/{key}', 'SupplierSyncLogApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_account/{key}', 'SupplierAccountApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_account/{key}', 'SupplierAccountApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_tag/{key}', 'SupplierTagApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_tag/{key}', 'SupplierTagApiController@Entrance');
......
...@@ -12,6 +12,7 @@ return [ ...@@ -12,6 +12,7 @@ return [
'SwitchWarehouse', 'SwitchWarehouse',
'SkuList', 'SkuList',
'BatchOffShelf', 'BatchOffShelf',
'AddSupplierAttachment',
]//不用验证权限的方法 ]//不用验证权限的方法
], ],
]; ];
{!! Autograph() !!}
<script>
layui.use(['form', 'upload', 'admin'], function () {
const form = layui.form
const upload = layui.upload;
const admin = layui.admin;
//提交数据
form.on('submit(addSupplierReceipt)', function (data) {
layer.confirm('确定要保存附件信息吗?', function (index) {
let res = ajax('/api/supplier_attachment/AddSupplierAttachment', data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
admin.putTempData("needFreshList", 1);
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
parent.layer.msg(res.err_msg, {icon: 5});
}
}
return false;
});
return false;
})
form.on('radio(receipt_type)', function (data) {
if (data.value == 1) {
$('#swift_code_div').hide();
} else {
$('#swift_code_div').show();
}
});
//图片上传
upload.render({
elem: '.upload-img'
, url: UploadImgUrl
, field: 'upload'
, data: {
k1: k1,
k2: k2,
source: 1
}
, accept: 'file'
, exts: 'jpg|png|bmp|jpeg|zip|pdf'
, before: function (obj) {
layer.msg('加载中', {
icon: 16
, shade: 0.01
});
let item = this.item;
//预读本地文件示例,不支持ie8
obj.preview(function (index, file, result) {
});
}
, done: function (res) {
if (res.code === 200) {
layer.msg('上传成功', {icon: 6});
let item = this.item;
$('#' + item.attr('data-obj')).val(res.data[0]);
$('#certificate_url').text(res.data[0]);
return false;
} else {
layer.msg('上传失败', {icon: 5});
return false;
}
}
, error: function (res) {
layer.msg('上传失败', {icon: 5});
return false;
}
});
});
</script>
\ No newline at end of file
<script>
layui.use(['table', 'form', 'element', 'layer', 'admin', 'upload'], function () {
let table = layui.table;
let form = layui.form;
let admin = layui.admin;
let element = layui.element;
let upload = layui.upload;
let supplierId = getQueryVariable('supplier_id')
table.render({
elem: '#attachmentList',
url: '/api/supplier_attachment/getSupplierAttachmentList?supplier_id=' + supplierId,
method: 'post',
size: 'sm',
cellMinWidth: 80,//全局定义常规单元格的最小宽度
where: {
supplier_id: supplierId
},
width: '70%',
loading: true,
first: true,//不显示首页
last: false,//不显示尾页
cols: [[
@if($operate=='update')
{
type: 'radio',
},
@endif
{
field: 'name', title: '附件类型', align: 'center', width: 150
},
{field: 'file_name', title: '附件名称', align: 'center', width: 200},
{field: 'description', title: '附件说明', align: 'center', width: 250},
{field: 'validity', title: '有效期', align: 'center', width: 250},
{field: 'admin_name', title: '上传人', align: 'center', width: 100},
{field: 'create_time', title: '上传时间', align: 'center', width: 150},
]],
id: 'attachmentList',
page: {},
});
//新增银行弹窗
$("#add_attachment").click(function () {
layer.open({
type: 2,
content: '/supplier_attachment/AddSupplierAttachment?view=iframe&supplier_id=' + supplierId,
area: ['50%', '70%'],
title: '新增银行',
end: function () {
table.reload('attachmentList');
}
});
})
//修改银行弹窗
$("#update_attachment").click(function () {
let checkStatus = table.checkStatus('attachmentList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的银行数据', {icon: 5})
} else {
let attachmentId = data[0].attachment_id;
let supplierId = data[0].supplier_id;
layer.open({
type: 2,
content: '/supplier_attachment/UpdateSupplierAttachment?view=iframe&supplier_id=' + supplierId + '&attachment_id=' + attachmentId,
area: ['50%', '70%'],
title: '修改附件',
end: function () {
table.reload('attachmentList');
}
});
}
})
$("#delete_attachment").click(function () {
let checkStatus = table.checkStatus('attachmentList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的银行', {icon: 5})
} else {
layer.confirm('确定要删除该银行信息?', function (index) {
let attachmentId = data[0].attachment_id;
let res = ajax('/api/supplier_attachment/DeleteSupplierAttachment', {attachment_id: attachmentId})
if (res.err_code === 0) {
table.reload('attachmentList')
layer.msg(res.err_msg, {icon: 6})
openLogView();
} else {
layer.msg(res.err_msg, {icon: 5})
}
});
}
});
});
</script>
\ No newline at end of file
<style>
.layui-form-item {
margin-bottom: 5px;
}
</style>
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form" action="">
<input type="hidden" name="supplier_id" value="{{request()->get('supplier_id')}}">
<input type="hidden" name="id" value="{{request()->get('id')}}">
<div class="layui-form-item">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('name','附件类型','',
config('fixed.FileNameMapping'),['required'=>true]) !!}
</div>
<div class="layui-form-item">
<label class="layui-form-label">有效期 : </label>
<div class="layui-input-block">
<input type="radio" name="validity_type" lay-filter="validity_type" value="1" title="长期有效"
@if((!empty($attachment['validity_type'])&&$attachment['validity_type']==1)||empty($attachment))
checked
@endif
>
<input type="radio" name="validity_type" lay-filter="validity_type" value="2" title="自定义"
@if(!empty($attachment['validity_type'])&&$attachment['validity_type']==2)
checked
@endif
>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">附件说明 : </label>
<div class="layui-input-block block-42">
<textarea name="description" placeholder="请输入附件说明" class="layui-textarea">{{$attachment['description'] or ''}}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">
<span class="require">*</span>文件上传:
</label>
<div class="layui-input-block">
<input type="hidden" name="url" id="url"
value="{{$attachment['url'] or ''}}">
<button type="button" class="layui-btn upload-img" preview="preview" data-obj="certificate">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<a target="_blank" id="certificate_url"
href="{{$attachment['url'] or ''}}">{{$attachment['url'] or ''}}</a>
</div>
</div>
<div class="layui-form-item">
<div align="center" style="margin-top: 20px">
<button type="button" id="addSupplierReceipt" class="layui-btn layui-btn-info submit-loading"
lay-submit
lay-filter="addSupplierReceipt">确认
</button>
</div>
</div>
</form>
</div>
</div>
\ No newline at end of file
...@@ -42,6 +42,14 @@ ...@@ -42,6 +42,14 @@
<b>{{array_get(config('field.SupplierType'),$supplier['supplier_type'])}}</b> <b>{{array_get(config('field.SupplierType'),$supplier['supplier_type'])}}</b>
</div> </div>
</div> </div>
@if ($supplier['supplier_type'] == \App\Model\SupplierChannelModel::SUPPLIER_TYPE_TEMPORARY)
<div class="layui-form-item">
<label class="layui-form-label">申请原因 : </label>
<div class="layui-input-block block-42" style="padding-top: 7px">
<p>{{$supplier['apply_audit_reason']}}</p>
</div>
</div>
@endif
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">审核意见 : </label> <label class="layui-form-label">审核意见 : </label>
<div class="layui-input-block"> <div class="layui-input-block">
...@@ -55,14 +63,6 @@ ...@@ -55,14 +63,6 @@
<textarea name="reject_reason" placeholder="不同意时必须填写原因" class="layui-textarea"></textarea> <textarea name="reject_reason" placeholder="不同意时必须填写原因" class="layui-textarea"></textarea>
</div> </div>
</div> </div>
@if ($supplier['supplier_type'] == \App\Model\SupplierChannelModel::SUPPLIER_TYPE_TEMPORARY)
<div class="layui-form-item">
<label class="layui-form-label">申请原因 : </label>
<div class="layui-input-block block-42" style="padding-top: 7px">
<p>{{$supplier['apply_audit_reason']}}</p>
</div>
</div>
@endif
<div class="layui-form-item"> <div class="layui-form-item">
<div align="center" style="margin-top: 20px;text-align: right"> <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 <button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
......
...@@ -161,6 +161,10 @@ ...@@ -161,6 +161,10 @@
</blockquote> </blockquote>
@include('web.supplier.SupplierReceipt') @include('web.supplier.SupplierReceipt')
<blockquote class="layui-elem-quote layui-text"> <blockquote class="layui-elem-quote layui-text">
<b>附件管理</b>
</blockquote>
@include('web.supplier.SupplierAttachment')
<blockquote class="layui-elem-quote layui-text">
<b>运输信息</b> <b>运输信息</b>
</blockquote> </blockquote>
<div class="layui-form-item"> <div class="layui-form-item">
......
<div class="layui-row">
@if($operate == 'update')
<div class="layui-btn-group demoTable" style="margin-top: 5px">
<button type="button" class="layui-btn layui-btn-sm" id="add_attachment">上传</button>
<button type="button" class="layui-btn layui-btn-sm" id="update_attachment">修改</button>
<button type="button" class="layui-btn layui-btn-sm" id="delete_attachment">删除</button>
</div>
@endif
<table class="layui-table" lay-filter="attachmentList" id="attachmentList"></table>
</div>
@include('script.supplier.SupplierAttachmentScript')
\ No newline at end of file
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