Commit 51920721 by 杨树贤

附件增删查

parent 1460ab41
......@@ -4,9 +4,11 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Services\SupplierAttachmentService;
use App\Http\Transformers\SupplierAttachmentTransformer;
use App\Http\Validators\SupplierAttachmentValidator;
use App\Model\LogModel;
use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierAttachmentModel;
use Illuminate\Http\Request;
......@@ -23,17 +25,17 @@ class SupplierAttachmentApiController extends Controller
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new SupplierAttachmentModel();
$model = new SupplierAttachmentsModel();
$model->where('supplier_id', $supplierId)->paginate();
$attachmentData = $model->where('supplier_id', $supplierId)->orderBy('id', 'desc')
->first();
$list = $model->where('supplier_id', $supplierId)->orderBy('attachment_id', 'desc')
->paginate($limit)->toArray();
$transformer = new SupplierAttachmentTransformer();
$list = $transformer->transformList($attachmentData);
$this->response(0, 'ok', $list, count($list));
$list['data'] = $transformer->transformList($list['data']);
$this->response(0, 'ok', $list['data'], $list['total']);
}
//获取供应商信息变更记录
public function AddSupplierAttachment($request)
public function SaveSupplierAttachment($request)
{
//先去表单验证
$validator = new SupplierAttachmentValidator();
......@@ -42,54 +44,26 @@ class SupplierAttachmentApiController extends Controller
$this->response(-1, $validateResult);
}
$attachment = $request->only([
'attachment_id',
'field_name',
'validity_type',
'validity_period',
'description',
'file_name',
'file_url',
'supplier_id',
'attachment_type',
'bank_name',
'bank_adderss',
'account_no',
'account_adderss',
'swift_code',
'certificate',
'account_name',
'remark',
'attachment_id',
]);
$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);
$attachmentService = new SupplierAttachmentService();
$result = $attachmentService->saveAttachment($attachment);
if (!$result) {
$this->response(-1, '操作失败');
} 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']) ? '修改银行信息' : '添加银行信息';
$content = !empty($attachment['attachment_id']) ? '修改附件信息' : '添加附件信息';
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
$this->response(0, '操作成功');
$this->response();
}
$this->response(-1, '操作失败');
}
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
......@@ -114,9 +88,14 @@ class SupplierAttachmentApiController extends Controller
public function DeleteSupplierAttachment($request)
{
$attachmentId = $request->get('attachment_id');
$model = new SupplierAttachmentModel();
$model = new SupplierAttachmentsModel();
$attachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
$result = $model->where('attachment_id', $attachmentId)->delete();
if ($result) {
$logService = new LogService();
$content = "删除附件信息 : " . $attachment['type_name'];
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '删除附件信息', $content, $remark);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
......
......@@ -8,6 +8,7 @@ use App\Http\Services\SupplierService;
use App\Http\Services\SupplierStatisticsService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierAttachmentModel;
use Illuminate\Http\Request;
......@@ -52,10 +53,13 @@ class SupplierAttachmentController extends Controller
//供应商详情
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();
$attachmentId = $request->get('attachment_id');
if (!empty($attachmentId)) {
$model = new SupplierAttachmentsModel();
$attachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
$attachment['validity_period'] = $attachment['validity_start'] ? date('Y-m-d',
$attachment['validity_start']) . '~' . date('Y-m-d', $attachment['validity_start']) : '';
$this->data['attachment'] = $attachment;
}
$this->data['title'] = '修改附件';
$this->data['view'] = 'AddSupplierAttachment';
......
......@@ -10,6 +10,7 @@ use App\Model\LogModel;
use App\Model\RedisModel;
use App\Model\StandardBrandModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
......@@ -467,6 +468,10 @@ class DataService
}
}
/*
* 供应商0.5版本下面需要跑的数据方法
* */
//转移付款方式到新添加的付款方式
public function TransferPayTypeDataToNewTable()
{
......@@ -501,13 +506,6 @@ class DataService
SupplierPayTypeModel::insert($payTypeData);
}
//将未转正的供应商的供应商类型改成未转正
public function changeSupplierTypeFromIsType()
{
SupplierChannelModel::where('is_type', 1)->update([
'supplier_type' => 3,
]);
}
//临时供应商标记以及等级切换
public function makeTempTagForSupplier()
......@@ -553,6 +551,52 @@ class DataService
'supplier_type' => 3
]);
}
//转移附件数据到新的表
public function transferAttachmentToNewTable()
{
$supplierAttachments = SupplierAttachmentModel::get()->toArray();
foreach ($supplierAttachments as $supplierAttachment) {
$supplierId = $supplierAttachment['supplier_id'];
if (SupplierAttachmentsModel::where('supplier_id',$supplierId)->exists()) {
continue;
}
$fields = [
'business_license',
'billing_information',
'registration_certificate',
'incorporation_certificate',
'certification_notice',
'supplier_survey',
'proxy_certificate',
'quality_assurance_agreement',
'confidentiality_agreement',
'cooperation_agreement',
'other_attachment',
];
$attachmentData = [];
foreach ($fields as $field) {
if (isset($supplierAttachment[$field]) && !empty($supplierAttachment[$field])) {
$supplierAttachment[$field] = json_decode($supplierAttachment[$field], true);
foreach ($supplierAttachment[$field] as $item) {
/*
* [{"name":"business_license","url":"http:\/\/img.ichunt.com\/test\/images\/ichunt\/202106\/25\/fc9c8179aa327f878932dd6b62b4d88c.png","file_name":"38.png"}]
* */
$attachmentData[] = [
'supplier_id' => $supplierId,
'type_name' => array_get(config('fixed.FileNameMapping'), $item['name']),
'field_name' => $item['name'],
'file_url' => $item['url'],
'file_name' => array_get($item,'file_name',''),
];
}
}
}
SupplierAttachmentsModel::insert($attachmentData);
}
}
}
......@@ -7,6 +7,7 @@ namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\RedisModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel;
use Illuminate\Support\Facades\DB;
//用于判断是否已经查看的服务
......@@ -19,7 +20,7 @@ class SupplierAttachmentService
$attachmentData = $attachmentModel->where('supplier_id', $supplierId)->first();
$attachment = [];
if (!empty($attachmentData)) {
$attachment = json_decode($attachmentData,true);
$attachment = json_decode($attachmentData, true);
$attachment = array_map(function ($item) {
return json_decode($item, true);
}, $attachment);
......@@ -27,17 +28,28 @@ class SupplierAttachmentService
return $attachment;
}
public function saveAttachment($supplierId, $attachment)
public function saveAttachment($attachment)
{
$attachmentModel = new SupplierAttachmentModel();
$attachmentData = $attachmentModel->where('supplier_id', $supplierId)->first();
if (!empty($attachmentData)) {
$attachment['update_time'] = time();
$attachmentModel->where('supplier_id', $supplierId)->update($attachment);
}else{
if ($attachment['validity_period']) {
$validityPeriod = explode('~', $attachment['validity_period']);
$attachment['validity_start'] = strtotime(trim($validityPeriod[0]));
$attachment['validity_end'] = strtotime(trim($validityPeriod[1]));
}
if ($attachment['validity_type']==1) {
$attachment['validity_start'] = $attachment['validity_end'] = 0;
}
$attachment['type_name'] = array_get(config('fixed.FileNameMapping'), $attachment['field_name']);
unset($attachment['validity_period']);
$attachmentId = $attachment['attachment_id'];
$attachmentModel = new SupplierAttachmentsModel();
if (empty($attachmentId)) {
$attachment['create_uid'] = request()->user->userId;
$attachment['create_name'] = request()->user->name;
$attachment['create_time'] = time();
$attachment['supplier_id'] = $supplierId;
$attachmentModel->insert($attachment);
return $attachmentModel->insertGetId($attachment);
} else {
$attachment['update_time'] = time();
return $attachmentModel->where('attachment_id', $attachmentId)->update($attachment);
}
}
}
\ No newline at end of file
......@@ -209,10 +209,6 @@ class SupplierService
$oldCustomerTags);
}
//保存附件
$attachmentService = new SupplierAttachmentService();
$attachmentService->saveAttachment($supplierId, $attachment);
//重新生成外部显示的编码
$this->generateSupplierSn($supplierId, $channel['supplier_group']);
//保存和搜索相关的标签情况
......
......@@ -6,48 +6,28 @@ namespace App\Http\Transformers;
class SupplierAttachmentTransformer
{
public function transformList($attachmentData)
public function transformList($list)
{
if (empty($attachmentData)) {
if (empty($list)) {
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) {
foreach ($list 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',
if ($attachment['validity_type'] == 1) {
$attachment['validity_period'] = '长期有效';
} else {
$attachment['validity_period'] = $attachment['validity_start'] ? date('Y-m-d',
$attachment['validity_start']) . '~' . date('Y-m-d', $attachment['validity_end']) : '';
}
$attachment['create_time'] = $attachment['create_time'] ? date('Y-m-d H:i:s',
$attachment['create_time']) : '';
}
unset($attachment);
return $attachmentList;
return $list;
}
}
\ No newline at end of file
......@@ -15,16 +15,12 @@ class SupplierAttachmentValidator
//整理下请求数据
$receipt = $request->all();
$rules = [
"bank_name" => "required",
"bank_adderss" => "required",
"account_no" => "required",
"receipt_type" => 'required',
// "account_name" => "required",
"certificate" => "required",
'field_name' => 'required',
'validity_type' => 'required',
'file_url' => 'required',
'file_name' => 'required',
];
if ($receipt['receipt_type'] == 2) {
$rules["swift_code"] = 'required';
}
$messages = $this->messages();
$validator = Validator::make($receipt, $rules, $messages);
......@@ -37,13 +33,10 @@ class SupplierAttachmentValidator
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' => '银行信息凭证不能为空',
'field_name.required' => '附件类型不能为空',
'validity.required' => '有效期类型不能为空',
'file_url.required' => '上传文件不能为空',
'file_name.required' => '文件名不能为空',
];
}
}
\ No newline at end of file
......@@ -52,5 +52,5 @@ Route::group(['middleware' => ['external'],'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService();
$service->makeTempTagForSupplier();
$service->transferAttachmentToNewTable();
});
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class SupplierAttachmentsModel extends Model
{
protected $connection='web';
protected $table='supplier_attachments';
protected $primaryKey = 'id';
public $timestamps = false;
}
......@@ -13,6 +13,7 @@ return [
'SkuList',
'BatchOffShelf',
'AddSupplierAttachment',
'UpdateSupplierAttachment',
]//不用验证权限的方法
],
];
{!! Autograph() !!}
<script>
layui.use(['form', 'upload', 'admin'], function () {
layui.use(['form', 'upload', 'admin', 'laydate'], function () {
const form = layui.form
const upload = layui.upload;
const admin = layui.admin;
//提交数据
form.on('submit(addSupplierReceipt)', function (data) {
form.on('submit(saveSupplierAttachment)', function (data) {
layer.confirm('确定要保存附件信息吗?', function (index) {
let res = ajax('/api/supplier_attachment/AddSupplierAttachment', data.field);
let res = ajax('/api/supplier_attachment/SaveSupplierAttachment', data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
......@@ -25,17 +25,46 @@
return false;
})
form.on('radio(receipt_type)', function (data) {
let laydate = layui.laydate;
@if (!empty($attachment['validity_period']))
laydate.render({
elem: 'input[name=validity_period]'
, type: 'date'
, trigger: 'click'
, range: '~' //或 range: '~' 来自定义分割字符
, value: '{{$attachment['validity_period']}}'
});
@else
laydate.render({
elem: 'input[name=validity_period]'
, type: 'date'
, trigger: 'click'
, range: '~' //或 range: '~' 来自定义分割字符
, value: ''
});
@endif
@if (!empty($attachment['validity_type'])&&$attachment['validity_type']==2)
$('#validity_period_div').show();
@else
$('#validity_period_div').hide();
@endif
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
form.on('radio(validity_type)', function (data) {
if (data.value == 1) {
$('#swift_code_div').hide();
$('#validity_period_div').hide();
} else {
$('#swift_code_div').show();
$('#validity_period_div').show();
}
});
let fileName = '';
//图片上传
upload.render({
elem: '.upload-img'
elem: '.upload-attachment'
, url: UploadImgUrl
, field: 'upload'
, data: {
......@@ -45,6 +74,11 @@
}
, accept: 'file'
, exts: 'jpg|png|bmp|jpeg|zip|pdf'
, choose: function (obj) {
let files = this.files = obj.pushFile();
let recentFile = files[Object.keys(files)[Object.keys(files).length - 1]]
fileName = recentFile.name;
}
, before: function (obj) {
layer.msg('加载中', {
icon: 16
......@@ -56,12 +90,15 @@
});
}
, done: function (res) {
, done: function (res, index, upload) {
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]);
$('#file_url_href').text(fileName);
$('#file_name').val(fileName);
$('#file_url').val(res.data[0]);
delete this.files[index];
return false;
} else {
layer.msg('上传失败', {icon: 5});
......
......@@ -27,12 +27,12 @@
},
@endif
{
field: 'name', title: '附件类型', align: 'center', width: 150
field: 'type_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: 'validity_period', title: '有效期', align: 'center', width: 250},
{field: 'create_name', title: '上传人', align: 'center', width: 100},
{field: 'create_time', title: '上传时间', align: 'center', width: 150},
]],
id: 'attachmentList',
......@@ -57,13 +57,13 @@
let checkStatus = table.checkStatus('attachmentList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的银行数据', {icon: 5})
layer.msg('请先选择要操作的附件', {icon: 5})
} else {
let attachmentId = data[0].attachment_id;
let attachment_id = 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,
content: '/supplier_attachment/UpdateSupplierAttachment?view=iframe&supplier_id=' + supplierId + '&attachment_id=' + attachment_id,
area: ['50%', '70%'],
title: '修改附件',
end: function () {
......@@ -77,9 +77,9 @@
let checkStatus = table.checkStatus('attachmentList');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的银行', {icon: 5})
layer.msg('请先选择要操作的附件', {icon: 5})
} else {
layer.confirm('确定要删除该银行信息?', function (index) {
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) {
......
......@@ -7,10 +7,10 @@
<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')}}">
<input type="hidden" name="attachment_id" value="{{request()->get('attachment_id')}}">
<div class="layui-form-item">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('name','附件类型','',
{!! $statusPresenter->render('field_name','附件类型',isset($attachment['field_name'])?$attachment['field_name']:'',
config('fixed.FileNameMapping'),['required'=>true]) !!}
</div>
<div class="layui-form-item">
......@@ -26,34 +26,44 @@
checked
@endif
>
<div id="validity_period_div" style="display: none">
<input type="text" name="validity_period"
placeholder="请选择时间区间" autocomplete="off" class="layui-input">
</div>
</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>
<textarea name="description" placeholder="请输入附件说明"
class="layui-textarea">{{$attachment['description'] or ''}}</textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-form-item" style="margin-top: 20px">
<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 ''}}">
<input type="hidden" name="file_url" id="file_url"
value="{{$attachment['file_url'] or ''}}">
<button type="button" class="layui-btn upload-img" preview="preview" data-obj="certificate">
<button type="button" class="layui-btn upload-attachment layui-btn-sm" preview="preview">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<a target="_blank" id="certificate_url"
href="{{$attachment['url'] or ''}}">{{$attachment['url'] or ''}}</a>
<a target="_blank" id="file_url_href"
href="{{$attachment['file_url'] or ''}}">{{$attachment['file_name'] or ''}}</a>
<input type="hidden" name="file_name" id="file_name" value="{{$attachment['file_name'] or ''}}">
</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">确认
<div align="center" style="margin-top: 20px;text-align: right">
<button type="button" id="saveSupplierAttachment" lay-filter="saveSupplierAttachment"
class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
>确认
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
lay-filter="cancel">取消
</button>
</div>
</div>
......
......@@ -153,9 +153,6 @@
<div class="layui-col-md3">
</div>
</div>
<hr/>
@include('web.supplier.SupplierPayType')
<hr/>
<blockquote class="layui-elem-quote layui-text">
<b>财务信息</b>
</blockquote>
......
......@@ -208,9 +208,6 @@
</div>
</div>
</div>
@include('web.supplier.SupplierFile')
@if($operate!='add' && checkPerm('UpdateSupplierTags'))
<blockquote class="layui-elem-quote layui-text">
<b>供应商标签 : </b>
......
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