Commit 3485bffb by 杨树贤

申请审核理由修改

parent 5f8b0d32
......@@ -94,7 +94,12 @@ class SupplierApiController extends Controller
{
//先去表单验证
$validator = new SupplierValidator();
$validateResult = $validator->checkSave($request);
$data = $request->all();
if (request()->get('direct_apply')) {
$validateResult = $validator->checkSave($data, true);
} else {
$validateResult = $validator->checkSave($data, false);
}
if ($validateResult) {
$this->response(-1, $validateResult);
}
......@@ -126,7 +131,8 @@ class SupplierApiController extends Controller
{
//先去表单验证
$validator = new SupplierValidator();
$validateResult = $validator->checkSave($request);
$data = $request->all();
$validateResult = $validator->checkSave($data, false);
if ($validateResult) {
$this->response(-1, $validateResult);
}
......@@ -405,6 +411,23 @@ class SupplierApiController extends Controller
}
}
//检查能否能申请审核
public function CheckCanApplyInReview($request)
{
$supplierIds = $request->get('supplier_ids');
if (!$supplierIds) {
$this->response(-1, '请选择供应商');
}
$supplierIds = explode(',', $supplierIds);
$supplierAuditService = new SupplierAuditService();
$check = $supplierAuditService->CheckCanApplyInReview($supplierIds);
if ($check === true) {
$this->response(0, '可以申请审核');
} else {
$this->response(-1, $check);
}
}
//检查能否审核(只有最后一次修改人和当前审核人是属于同部门的,才能审核)
public function CheckCanAuditSupplier($request)
{
......
......@@ -13,6 +13,7 @@ use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Log;
......@@ -507,6 +508,51 @@ class DataService
'supplier_type' => 3,
]);
}
//临时供应商标记以及等级切换
public function makeTempTagForSupplier()
{
/*
创建时间为2021-06-01开始截至现在,供应商类别为正式/临时,供应商性质为现货商,且没有上传品质协议,系统标签需要贴【临时供应商标签】,等级标记为E
创建时间为空,不在上述供应商集内
*/
$time = strtotime("2021-06-01");
$suppliers = SupplierChannelModel::where('create_time', '>', $time)->where('is_type', 0)->where('create_time',
'!=', 0)
->get();
foreach ($suppliers as $supplier) {
$supplierId = $supplier['supplier_id'];
//判断是否有上传品质协议
$hasQualityAssuranceAgreement = SupplierAttachmentModel::where('supplier_id',
$supplierId)->value('quality_assurance_agreement');
//供应商性质为现货商,且没有上传品质协议,系统标签需要贴【临时供应商标签】,等级标记为E
if (!$hasQualityAssuranceAgreement && $supplier['supplier_group'] == 2) {
$tagService = new SupplierTagService();
$oldTags = $supplier['system_tags'];
if (strpos($supplier['system_tags'], '临时供应商') !== false) {
continue;
}
$newTags = $supplier['system_tags'] ? rtrim($supplier['system_tags'], ',') . ',临时供应商' : '临时供应商';
if ($tagService->saveTags($supplierId, 14, $newTags, $oldTags)) {
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'system_tags' => $newTags,
'level' => 'E'
]);
}
}
}
}
//将非正式供应商(is_type=1)的类别设置为待转正
public function changeSupplierTypeByIsType()
{
SupplierChannelModel::where('is_type', 1)->update([
'supplier_type' => 3
]);
}
}
......@@ -3,6 +3,7 @@
namespace App\Http\Services;
use App\Http\Validators\SupplierValidator;
use App\Model\LogModel;
use App\Model\RedisModel;
use App\Model\SupplierAttachmentModel;
......@@ -90,6 +91,20 @@ class SupplierAuditService
return $result;
}
public function CheckCanApplyInReview($supplierIds)
{
foreach ($supplierIds as $supplierId) {
$supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first()->toArray();
$validator = new SupplierValidator();
$check = $validator->checkSave($supplier, true);
if ($check) {
return '供应商 : [ ' . $supplier['supplier_name'] . ' ] 必要信息填写不完整,请完善必填信息,原因 : '.$check;
}
return true;
}
}
//判断是否是可以由当前用户审核
//要判断审核供应商的最后修改人,是不是属于当前审批人的部门或者部下,是才能让他审核
public function CheckCanAuditSupplier($supplierId)
......@@ -215,27 +230,6 @@ class SupplierAuditService
return true;
}
//判断付款方式是否发生变化,如果有变化也要进入审核
$oldPayTypeData = SupplierPayTypeModel::where('supplier_id', $supplierId)->get();
if (empty($oldPayTypeData) && $payTypeData) {
return true;
} else {
$oldPayTypeData = $oldPayTypeData->toArray();
$oldPayTypeData = array_map(function ($data) {
unset($data['id']);
return $data;
}, $oldPayTypeData);
$payTypeData = SupplierPayTypeService::getSupplierPayTypeListDBData($supplierId, $payTypeData);
if (count($oldPayTypeData) != count($payTypeData)) {
return true;
}
foreach ($oldPayTypeData as $key => $data) {
if (array_diff($data, array_get($payTypeData, $key))) {
return true;
}
}
}
$supplier = $model->select($selectField)->where('supplier_id', $supplierId)->first()->toArray();
$changeField = [];
foreach ($supplier as $key => $value) {
......
......@@ -9,62 +9,4 @@ use App\Model\SupplierPayTypeModel;
class SupplierPayTypeService
{
public static function getPayTypeNames($payType)
{
$payTypeList = explode(',', $payType);
if (empty($payTypeList)) {
return '';
}
$payTypeNameArr = [];
foreach ($payTypeList as $payType) {
$payTypeNameArr[] = array_get(config('fixed.SupplierPayType'), $payType);
}
return implode(',', $payTypeNameArr);
}
public static function getSupplierPayTypeList($supplierId)
{
$payTypeList = SupplierPayTypeModel::where('supplier_id', $supplierId)->get();
$payTypeList = !empty($payTypeList) ? $payTypeList->toArray() : [];
return $payTypeList;
}
//获取一个付款类型列表,用逗号隔开的值存到主表(为了方便查询)
public static function getSupplierPayTypeForChannelDB($channel)
{
$payTypeList = array_get($channel, 'pay_type');
$payType = implode(',', $payTypeList);
return $payType;
}
public static function getSupplierPayTypeListDBData($supplierId,$payTypeData)
{
$payTypeList = array_get($payTypeData, 'pay_type');
$payTypeValueList = array_get($payTypeData, 'pay_type_value');
$payTypeExtraList = array_get($payTypeData, 'pay_type_extra');
$payTypeData = [];
foreach ($payTypeList as $key => $payType) {
$payTypeData[] = [
'pay_type' => $payType,
'pay_type_value' => $payTypeValueList[$key],
'pay_type_extra' => $payTypeExtraList[$key],
'supplier_id' => $supplierId,
];
}
return $payTypeData;
}
//保存付款方式列表
public static function saveSupplierPayTypeList($supplierId, $payTypeData)
{
$payTypeData = self::getSupplierPayTypeListDBData($supplierId, $payTypeData);
//先删除数据库里面的付款方式
$deleteResult = SupplierPayTypeModel::where('supplier_id', $supplierId)->delete();
if ($deleteResult !== false) {
//插入到数据库
SupplierPayTypeModel::insert($payTypeData);
}
}
}
\ No newline at end of file
......@@ -155,8 +155,6 @@ class SupplierService
}
$channel['update_time'] = time();
$channel['pay_type'] = SupplierPayTypeService::getSupplierPayTypeForChannelDB($payTypeData);
//这里有个逻辑,就是如果供应商类型是临时,那么要打上临时供应商的标签,如果不是,那么就要去掉这个标签
if ($channel['supplier_type'] == SupplierChannelModel::SUPPLIER_TYPE_TEMPORARY) {
......@@ -209,8 +207,7 @@ class SupplierService
$oldSystemTags);
$tagService->saveTags($supplierId, SupplierTagService::TAG_TYPE_CUSTOMER, $channel['customer_tags'],
$oldCustomerTags);
//保存付款方式列表
SupplierPayTypeService::saveSupplierPayTypeList($supplierId, $payTypeData);
}
//保存附件
......@@ -434,6 +431,7 @@ class SupplierService
$result = $model->where('supplier_id', $supplierId)->update([
'update_time' => time(),
'is_type' => $isType,
// 'supplier_type'=> 1,
'status' => SupplierChannelModel::STATUS_PENDING,
]);
if ($result) {
......
......@@ -102,7 +102,7 @@ class SupplierTransformer
$supplier['region_name'] = array_get(config('fixed.Region'), $supplier['region']);
$supplier['currency_name'] = array_get(config('fixed.Currency'), $supplier['currency']);
$supplier['supplier_group_name'] = array_get(config('fixed.SupplierGroup'), $supplier['supplier_group']);
$supplier['pay_type_name'] = SupplierPayTypeService::getPayTypeNames($supplier['pay_type']);
$supplier['pay_type_name'] = array_get(config('fixed.SupplierPayType'),$supplier['pay_type']);
$supplier['trading_method_name'] = array_get(config('fixed.TradingMethod'), $supplier['trading_method']);
$supplier['main_brand_names'] = $this->getMainBrandNames($supplier['main_brands']);
$supplier['update_time'] = $supplier['update_time'] ? date('Y-m-d H:i:s', $supplier['update_time']) : '';
......@@ -120,7 +120,6 @@ class SupplierTransformer
$supplier['extra_fee'] = $ExtendModel->getExtendExtra($supplier['supplier_code'], $supplier['supplier_id']);
//获取供应商地址信息
$supplier = $this->getSupplierAddress($supplier);
$supplier['pay_type_list'] = SupplierPayTypeService::getSupplierPayTypeList($supplier['supplier_id']);
$supplier['supplier_type_name'] = array_get(config('field.SupplierType'), $supplier['supplier_type']);
//获取最近修改信息
$logModel = new LogModel();
......
......@@ -4,6 +4,7 @@
namespace App\Http\Validators;
use App\Http\Services\SupplierPayTypeService;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use Validator;
......@@ -12,11 +13,31 @@ class SupplierValidator
{
//保存相关的验证,别问我为什么不用laravel自带的form-request类
//因为控制器那边已经被之前的人魔改的难用的一比,而且控制器那边还接收了一大堆统一变量
public function checkSave($request)
public function checkSave($validateData, $isAudit)
{
//整理下请求数据
$requestData = $request->all();
$requestData = $this->transformRequestData($requestData);
$validateData = $this->transformRequestData($validateData);
$supplierId = $validateData['supplier_id'];
//如果是直接提交,不是点申请审核的,只需要校验供应商名称是否存在即可
if (!$isAudit) {
if (empty($validateData['supplier_name'])) {
return '供应商名称不能为空';
}
if (empty($supplierId)) {
$count = SupplierChannelModel::where('supplier_name', $validateData['supplier_name'])->count();
} else {
$count = SupplierChannelModel::where('supplier_name', $validateData['supplier_name'])
->where('supplier_id', '!=', $supplierId)->count();
}
if ($count) {
return "该供应商名称已经存在,请核验后再提交";
}
return null;
}
$rules = [
'supplier_type' => 'required',
'supplier_name' => 'required',
......@@ -47,7 +68,11 @@ class SupplierValidator
];
//只有在提交供应商是正式的时候,才会去校验附件
if ($requestData['supplier_type'] == 1) {
if ($validateData['supplier_type'] == 1) {
//产品要把表单校验改成审核的时候才去校验,这个时候附件就要单独去取值了,要不然这个时候提交上来的肯定没有附件信息
$attachments = SupplierAttachmentModel::where('supplier_id', $supplierId)->first();
$attachments = !empty($attachments) ? $attachments->toArray() : [];
$validateData = array_merge($validateData, $attachments);
//校验附件,只要营业执照、商业登记证、公司注册证至少其中一个上传了附件,就判定已经上传了附件
$attachmentValidateFields = [
'business_license',
......@@ -56,7 +81,7 @@ class SupplierValidator
];
$attachmentValidateFieldsExist = false;
foreach ($attachmentValidateFields as $field) {
if (array_get($requestData, $field)) {
if (array_get($validateData, $field)) {
$attachmentValidateFieldsExist = true;
break;
}
......@@ -66,8 +91,8 @@ class SupplierValidator
}
//如果供应商性质是现货商,那么品质协议也不能为空
if ($requestData['supplier_group'] == 2) {
if (empty($requestData['quality_assurance_agreement'])) {
if ($validateData['supplier_group'] == 2) {
if (empty($validateData['quality_assurance_agreement'])) {
return '该供应商为现货商,请上传品质协议!';
}
}
......@@ -75,41 +100,38 @@ class SupplierValidator
//第一次新增的时候,是要校验联系人的
if (empty($requestData['supplier_id'])) {
if (empty($validateData['supplier_id'])) {
$rules = array_merge($rules, $contactRuler);
}
//币种为人民币的话需要验证税号
if ($requestData['currency'] == 1) {
if ($validateData['currency'] == 1) {
$rules['tax_number'] = 'required';
}
//新增的时候,渠道开发不能为空
if (empty($requestData['supplier_id'])) {
if (empty($validateData['supplier_id'])) {
$rules['purchase_uid'] = 'required';
}
$messages = $this->messages();
$validator = Validator::make($requestData, $rules, $messages);
$validator = Validator::make($validateData, $rules, $messages);
if ($validator->fails()) {
return $validator->errors()->first();
}
$supplierId = $request->get('supplier_id');
//检验名称是否已经存在数据库
$supplierModel = new SupplierChannelModel();
$contactModel = new SupplierContactModel();
$companyNameCount = 0;
if (empty($supplierId)) {
$count = $supplierModel->where('supplier_name', $request->get('supplier_name'))->count();
$companyNameCount = $supplierModel->where('register_company_name',
$request->get('register_company_name'))->where('register_company_name', '!=', '')->count();
$count = SupplierChannelModel::where('supplier_name', $validateData['supplier_name'])->count();
$companyNameCount = SupplierChannelModel::where('register_company_name',
$validateData['register_company_name'])->where('register_company_name', '!=', '')->count();
} else {
$count = $supplierModel->where('supplier_name', $request->get('supplier_name'))
$count = SupplierChannelModel::where('supplier_name', $validateData['supplier_name'])
->where('supplier_id', '!=', $supplierId)->count();
//至少要有一个联系方式
$contactCount = $contactModel->where('supplier_id', $supplierId)->count();
$contactCount = SupplierContactModel::where('supplier_id', $supplierId)->count();
if (!$contactCount) {
return "供应商至少要有一个联系人,请补全";
}
......@@ -123,8 +145,8 @@ class SupplierValidator
if (!empty($supplierId)) {
//还要去判断当前提交人是否存在与其关联的联系人没有完善
$codeId = $request->user->codeId;
$notCompleteContacts = $contactModel->where('supplier_id', $supplierId)
$codeId = request()->user->codeId;
$notCompleteContacts = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $codeId)
->where(function ($q) {
$q->where('supplier_consignee', '')
......@@ -137,22 +159,7 @@ class SupplierValidator
if ($notCompleteContacts) {
return "存在和你相关的联系人没有完善,请先去完善相关联系人";
}
//判断付款方式
//获取付款类型有关的数据
$payTypeData = array_only($requestData, ['pay_type', 'pay_type_value', 'pay_type_extra']);
$payTypeData = SupplierPayTypeService::getSupplierPayTypeListDBData($supplierId, $payTypeData);
foreach ($payTypeData as $key => $payType) {
//非货到付款的要判断value和extra
if ($payType['pay_type'] != 2) {
if (!$payType['pay_type_value'] || !$payType['pay_type_extra']) {
return "请补充完整付款方式信息";
}
}
}
}
}
private function messages()
......@@ -198,8 +205,13 @@ class SupplierValidator
];
}
public function transformRequestData($requestData)
public function transformRequestData($validateData)
{
return $requestData;
foreach ($validateData as &$item) {
if (!is_array($item)) {
$item = trim($item);
}
}
return $validateData;
}
}
\ No newline at end of file
......@@ -50,5 +50,5 @@ Route::group(['middleware' => ['external'],'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService();
$service->changeSupplierTypeFromIsType();
$service->makeTempTagForSupplier();
});
......@@ -114,6 +114,7 @@ return [
'SupplierType' => [
1 => '正式',
2 => '临时',
3 => '待转正',
],
//TT(电汇)、支票、信用卡、其他
'SettlementType' => [
......@@ -121,5 +122,9 @@ return [
2 => '支票',
3 => '信用卡',
0 => '其他',
],
'ApplyAuditReason' => [
'拒签' => '拒签',
'候补' => '候补'
]
];
\ No newline at end of file
......@@ -4,23 +4,6 @@
let form = layui.form;
let table = layui.table
let element = layui.element;
// $('#batch_apply_in_review_supplier').click(function () {
// admin.btnLoading('.submit-loading');
// let supplierIds = getQueryVariable('supplier_ids');
// let url = '/api/supplier/BatchApplyInReviewSupplier?supplier_ids=' + supplierIds;
// let res = ajax(url);
// if (!res) {
// layer.msg('网络错误,请重试', {icon: 6});
// } else {
// if (res.err_code === 0) {
// admin.closeThisDialog();
// parent.layer.msg(res.err_msg, {icon: 6});
// } else {
// admin.btnLoading('.submit-loading', false);
// parent.layer.msg(res.err_msg, {icon: 5});
// }
// }
// });
form.on('submit(batch_apply_in_review_supplier)', function (data) {
let url = '/api/supplier/BatchApplyInReviewSupplier';
......
......@@ -130,13 +130,13 @@
{field: 'supplier_type_name', title: '供应商类别', align: 'center', width: 110},
];
@if(checkPerm('ViewFakeSupplier') && request()->user->userId == 1000)
cols.push({
field: 'is_type', title: '正式供应商', align: 'center', width: 110, templet: function (data) {
return data.is_type === 0 ? '正式' : '<span style="color: red">待转正</span>';
}
})
@endif
{{-- @if(checkPerm('ViewFakeSupplier') && request()->user->userId == 1000)--}}
{{-- cols.push({--}}
{{-- field: 'is_type', title: '正式供应商', align: 'center', width: 110, templet: function (data) {--}}
{{-- return data.is_type === 0 ? '正式' : '<span style="color: red">待转正</span>';--}}
{{-- }--}}
{{-- })--}}
{{-- @endif--}}
cols.push(
{field: 'create_time', title: '创建时间', align: 'center', width: 145},
);
......@@ -359,16 +359,22 @@
layer.msg('请先选择要操作的供应商', {icon: 5})
} else {
let status = Array.from(data, ({status}) => status);
let checkCanApplyInReview = true;
let canApplyInReview = true;
$.each(status, function (index, value) {
if (value !== 0) {
checkCanApplyInReview = false;
canApplyInReview = false;
}
});
if (!checkCanApplyInReview) {
if (!canApplyInReview) {
layer.msg('选择的供应商里,存在非待审核状态的供应商,无法申请审核', {icon: 5})
return false;
}
//还要去事先检测供应商信息是否完整
let checkApplyMsg = checkCanApplyInReview(supplierIds);
if (checkApplyMsg !== '') {
layer.msg(checkApplyMsg, {icon: 5});
return
}
layer.open({
type: 2,
content: '/supplier/BatchApplyInReviewSupplier?view=iframe&supplier_ids=' + supplierIds,
......@@ -581,6 +587,16 @@
}
}
function checkCanApplyInReview(supplierIds) {
let url = '/api/supplier/CheckCanApplyInReview?supplier_ids=' + supplierIds;
let res = ajax(url);
if (res.err_code !== 0) {
return res.err_msg;
} else {
return '';
}
}
function clearTypeFilter() {
$('.main_filter').attr('class', 'main_filter');
$('.status_filter').attr('class', 'status_filter');
......
......@@ -197,6 +197,7 @@
});
form.on('submit(addAndApplySupplier)', function (data) {
layer.confirm('确定直接申请审核吗?确定后会直接进入审核中的状态,无法进行二次修改', function (index) {
//还要判断
let url = '/api/supplier/AddSupplier?direct_apply=1';
......
......@@ -18,7 +18,7 @@
<tr>
<th>供应商名称</th>
<th>供应商类型</th>
<th>申请原因</th>
<th>申请原因(如果供应商类型为临时,则要填写申请原因)</th>
</tr>
</thead>
<tbody>
......@@ -33,14 +33,17 @@
<div class="layui-row">
<div class="layui-col-xs1">
<input type="hidden" name="supplier_type[]" value="{{$supplier['supplier_type']}}">
@if ($supplier['supplier_type']==\App\Model\SupplierChannelModel::SUPPLIER_TYPE_TEMPORARY)
@if ($supplier['supplier_type']==\App\Model\SupplierChannelModel::SUPPLIER_TYPE_TEMPORARY)
<span class="require">*</span>
@endif
</div>
<div class="layui-col-xs11"
@if ($supplier['supplier_type']==\App\Model\SupplierChannelModel::SUPPLIER_TYPE_TEMPORARY) style="margin-left: -15px" @endif>
<input type="text" name="apply_audit_reason[]"
placeholder="如果供应商类型为临时,则要填写申请原因" class="layui-input supplier_reason">
<div class="layui-col-xs11">
<select name="apply_audit_reason[]" lay-verify="required">
<option value="">请选择</option>
@foreach (config('field.ApplyAuditReason') as $item)
<option value="{{$item}}">{{$item}}</option>
@endforeach
</select>
</div>
......@@ -53,13 +56,14 @@
</table>
</div>
<div style="margin-top: 20px;text-align: right">
{{-- <button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading"--}}
{{-- id="batch_apply_in_review_supplier">确认--}}
{{-- </button>--}}
{{-- <button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading"--}}
{{-- id="batch_apply_in_review_supplier">确认--}}
{{-- </button>--}}
<button type="button" class="layui-btn layui-btn-sm submit-loading" lay-submit
lay-filter="batch_apply_in_review_supplier">确认
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="cancel" id="cancel">取消
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="cancel"
id="cancel">取消
</button>
</div>
</form>
</div>
......@@ -167,7 +167,7 @@
@if(checkPerm('ViewFakeSupplier'))
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('is_type','正式供应商','',[0=>'是',1=>'否']) !!}
{!! $statusPresenter->render('supplier_type','供应商类别','',config('field.SupplierType')) !!}
</div>
@endif
<div class="layui-inline">
......
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