Commit b216f1a4 by 杨树贤

付款方式批量修改

parent 0c61f249
......@@ -79,7 +79,8 @@ class SupplierApiController extends Controller
//付款方式
'pay_type',
'pay_detail',
'pay_type_value',
'pay_type_extra'
];
public function Entrance(Request $request, $id)
......@@ -130,7 +131,7 @@ class SupplierApiController extends Controller
}
$channelMap = array_merge($this->channelMap, config('field.AttachmentFields'));
$channel = $request->only($channelMap);
dd($channel);
// dd($channel);
$service = new SupplierService();
$result = $service->saveSupplier($channel);
if (!$result) {
......
......@@ -12,6 +12,7 @@ use App\Model\StandardBrandModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Log;
......@@ -378,7 +379,7 @@ class DataService
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$supplierService = new SupplierService();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel,$supplierService) {
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel, $supplierService) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]);
......@@ -415,6 +416,40 @@ class DataService
var_dump($exception);
}
}
//转移付款方式到新添加的付款方式
public function TransferPayTypeDataToNewTable()
{
ini_set('memory_limit','-1');
$suppliers = SupplierChannelModel::where('pay_type', '!=', '0')->get()->toArray();
$payTypeData = [];
foreach ($suppliers as $supplier) {
//3代表是全款,对应新表的预付款 100%
if ($supplier['pay_type'] == 3) {
$payTypeData[] = [
'supplier_id' => $supplier['supplier_id'],
'pay_type' => $supplier['pay_type'],
'pay_type_value' => 100,
'pay_type_extra' => '%',
];
} else {
$payTypeData[] = [
'supplier_id' => $supplier['supplier_id'],
'pay_type' => $supplier['pay_type'],
'pay_type_value' => '',
'pay_type_extra' => '天',
];
}
}
foreach ($payTypeData as $key => $data) {
//先检查是否存在
$exist = SupplierPayTypeModel::where('supplier_id', $data['supplier_id'])->exists();
if ($exist) {
unset($payTypeData[$key]);
}
}
SupplierPayTypeModel::insert($payTypeData);
}
}
......@@ -8,6 +8,7 @@ use App\Model\RedisModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
class SupplierAuditService
{
......@@ -170,7 +171,7 @@ class SupplierAuditService
}
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
public function checkNeedAudit($supplierId, $channel, $attachment)
public function checkNeedAudit($supplierId, $channel, $attachment, $payTypeData)
{
$notNeedAuditField = [
'register_company_name',
......@@ -200,6 +201,28 @@ class SupplierAuditService
if ($oldAttachment != $newAttachment) {
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) {
......
......@@ -8,10 +8,63 @@ 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
......@@ -71,16 +71,24 @@ class SupplierService
'hk' => $channel['hk'],
'cn' => $channel['cn'],
];
unset($channel['hk'], $channel['cn']);
//获取收发货地有关的数据
$address = array_only($channel,
['supplier_id', 'shipping_address', 'return_address', 'return_consignee', 'return_phone']);
$shippingAddress = array_get($channel, 'shipping_address');
$attachment = $channel['attachment'];
unset($channel['hk'], $channel['cn'], $channel['return_phone'], $channel['return_address'],
unset($channel['return_phone'], $channel['return_address'],
$channel['return_consignee'], $channel['shipping_address'], $channel['cn_delivery_time_period'],
$channel['us_delivery_time_period'], $channel['attachment']);
//获取付款类型有关的数据
$payTypeData = array_only($channel,['pay_type','pay_type_value','pay_type_extra']);
unset($channel['pay_type'], $channel['pay_type_value'], $channel['pay_type_extra']);
$skuAuditRulerService = new SupplierSkuAuditRulerService();
$channel['sku_audit_ruler'] = $skuAuditRulerService->getSkuAuditRulerForDB($channel['sku_audit_ruler']);
$channel['pay_type'] = SupplierPayTypeService::getSupplierPayTypeForChannelDB($payTypeData);
//新增供应商操作
if (empty($channel['supplier_id'])) {
//先去插入到channel表
......@@ -98,7 +106,7 @@ class SupplierService
//判断是否是直接添加并且申请审核
if (request()->get('direct_apply')) {
$channel['status'] = SupplierChannelModel::STATUS_IN_REVIEW;
}else{
} else {
$channel['status'] = SupplierChannelModel::STATUS_PENDING;
}
//第一次新增的供应商,都需要进行复审
......@@ -117,13 +125,14 @@ class SupplierService
$channel = array_except($channel, $contactField);
$channel['channel_uid'] = $contact['can_check_uids'];
$supplierId = $this->newSupplierId = $model->insertGetId($channel);
//同时添加联系人
$contact['supplier_id'] = $supplierId;
$contact['add_time'] = time();
$contact['admin_id'] = request()->user->userId;
$contactModel = new SupplierContactModel();
$contactModel->insert($contact);
//保存生成的内部编码
$this->saveSupplierCode($supplierId);
//新增的时候也要去添加地址了
......@@ -133,7 +142,7 @@ class SupplierService
$supplierId = $this->newSupplierId = $channel['supplier_id'];
//要做进一步判断,部分字段修改不需要审核
$auditService = new SupplierAuditService();
$needAudit = $auditService->checkNeedAudit($supplierId, $channel, $attachment);
$needAudit = $auditService->checkNeedAudit($supplierId, $channel, $attachment,$payTypeData);
if ($needAudit) {
$channel['status'] = SupplierChannelModel::STATUS_PENDING;
}
......@@ -158,6 +167,8 @@ class SupplierService
$tagService->saveTags($supplierId, 14, $channel['system_tags'], $oldSystemTags);
$tagService->saveTags($supplierId, 4, $channel['customer_tags'], $oldCustomerTags);
}
//保存付款方式列表
SupplierPayTypeService::saveSupplierPayTypeList($supplierId, $payTypeData);
//保存附件
$attachmentService = new SupplierAttachmentService();
$attachmentService->saveAttachment($supplierId, $attachment);
......
......@@ -101,7 +101,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'] = array_get(config('fixed.SupplierPayType'), $supplier['pay_type']);
$supplier['pay_type_name'] = SupplierPayTypeService::getPayTypeNames($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']) : '';
......
......@@ -3,6 +3,7 @@
namespace App\Http\Validators;
use App\Http\Services\SupplierPayTypeService;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use Validator;
......@@ -23,7 +24,6 @@ class SupplierValidator
'main_brands' => 'required',
'main_customers' => 'max:100',
'ticket_time' => 'max:20',
// 'supplier_address' => 'required',
'region' => 'required',
'cn_delivery_time' => 'regex:/^\d+\-\d$/',
'us_delivery_time' => 'regex:/^\d+\-\d$/',
......@@ -32,8 +32,6 @@ class SupplierValidator
'return_address' => 'max:100',
'return_consignee' => 'max:50',
'return_phone' => 'max:50',
// 'business_license' => 'required',
// 'established_time' => 'required',
'cn_ratio' => 'min:1',
'us_ratio' => 'min:1',
];
......@@ -121,8 +119,22 @@ 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()
......
......@@ -46,8 +46,9 @@ Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService();
// $service->pushSupplierSKu();
// $service->makeSupplierSystemTag();
$service->importSupplier();
// $service->importSupplier();
// $service->transferFileData();
$service->TransferPayTypeDataToNewTable();
// $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
// $service->replaceStandardBrandId();
});
......@@ -5,32 +5,48 @@
//要根据付款类型的不同选项,切换不同的显示
form.on('select(pay_type[])', function (data) {
const payType = data.value;
$('.pay_type_' + payType + '_div').show();
let parentDiv = $(this).parents('.pay_type_div');
parentDiv.find('.pay_type_' + payType + '_div').show();
parentDiv.find('.pay_type_' + payType + '_div').find('.valueInput').first().attr('name', 'pay_type_value[]');
parentDiv.find('.pay_type_' + payType + '_div').find('.valueInput').eq(1).attr('name', 'pay_type_extra[]');
if (payType === '1') {
$('.pay_type_2_div').hide();
$('.pay_type_3_div').hide();
parentDiv.find('.pay_type_2_div').hide();
parentDiv.find('.pay_type_2_div').find('.valueInput').attr('name', '');
parentDiv.find('.pay_type_3_div').hide();
parentDiv.find('.pay_type_3_div').find('.valueInput').attr('name', '');
form.render('select');
}
if (payType === '2') {
$('.pay_type_1_div').hide();
$('.pay_type_3_div').hide();
parentDiv.find('.pay_type_1_div').hide();
parentDiv.find('.pay_type_1_div').find('.valueInput').attr('name', '');
parentDiv.find('.pay_type_3_div').hide();
parentDiv.find('.pay_type_3_div').find('.valueInput').attr('name', '');
form.render('select');
}
if (payType === '3') {
$('.pay_type_1_div').hide();
$('.pay_type_2_div').hide();
parentDiv.find('.pay_type_1_div').hide();
parentDiv.find('.pay_type_1_div').find('.valueInput').attr('name', '');
parentDiv.find('.pay_type_2_div').hide();
parentDiv.find('.pay_type_2_div').find('.valueInput').attr('name', '');
form.render('select');
}
});
form.on('select(pay_type_month)', function (data) {
const value = data.value;
console.log($(this).parents('.layui-input-inline').find('.valueInput').val(value));
});
form.on('select(pay_type_3_type)', function (data) {
const value = data.value;
let parentDiv = $(this).parents('.pay_type_3_div');
if (value === '首款比例') {
parentDiv.find('.temp').text('%')
parentDiv.find('.temp').next().val('%')
}
if (value === '首款金额') {
parentDiv.find('.temp').text('RMB')
parentDiv.find('.temp').next().val('RMB')
}
});
......@@ -40,11 +56,19 @@
layer.msg('至少要保留一个付款方式', {icon: 5});
return;
}
$(this).parents('.pay_type_div').remove();
var self = $(this);
layer.confirm('确定要删除付款方式吗?', function (index) {
self.parents('.pay_type_div').remove();
layer.closeAll();
});
});
$(document).on('click', '.add_pay_type', function () {
$('#pay_type_div_list').append($('#pay_type_template').html());
//不知道为什么元素的name总会变来变去,所以手动固定死,确保提交的时候,顺序和名称都是对的
$("input[name^='pay_type_value[']").attr('name','pay_type_value[]')
$("input[name^='pay_type_extra[']").attr('name','pay_type_extra[]')
$("select[name^='pay_type[']").attr('name','pay_type[]')
form.render('select');
});
......
......@@ -229,6 +229,10 @@
</div>
<hr/>
<blockquote class="layui-elem-quote layui-text">
<b>付款方式</b>
</blockquote>
<hr/>
<blockquote class="layui-elem-quote layui-text">
<b>供应商标签</b>
</blockquote>
<div class="layui-row">
......
......@@ -9,38 +9,84 @@
</script>
@endif
<div id="pay_type_div_list">
<div style="margin-bottom: 10px;margin-top: 5px">
<button type="button" class="layui-btn layui-btn-sm add_pay_type">新增付款方式</button>
</div>
@if (!empty($supplier['pay_type_list']))
@foreach($supplier['pay_type_list'] as $payType)
<div class="layui-row pay_type_div" style="margin-bottom: 10px;">
<div class="layui-col-md2">
<div class="layui-row pay_type_div" style="margin-bottom: 5px;">
<div class="layui-col-md3">
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('pay_type[]','付款方式 : ',
$payType['pay_type'],config('fixed.SupplierPayType'),['required'=>false]) !!}
</div>
</div>
<input type="hidden" name="pay_type_extra">
<div class="layui-col-md10" style="width:500px;margin-bottom: 3px;">
<div class="layui-row">
@if ($payType['pay_type']==1)
<div class="pay_type_1_div">
<div class="layui-row" style="padding-left:80px">
月结&nbsp
<div class="layui-input-inline" style="width: 50px;">
<input class="layui-input" type="text" name="">
<div class="layui-row" style="padding-left:70px">
<span class="require">*</span>月结 : &nbsp
<div class="layui-input-inline" style="width: 80px;">
<input class="layui-input valueInput" type="hidden" name="pay_type_value[]"
value="{{$payType['pay_type_value'] or ''}}">
<select lay-filter="pay_type_month">
<option value="">请选择</option>
<option value="30"
@if($payType['pay_type_value']==30)
selected='selected'
@endif>30
</option>
<option value="60"
@if($payType['pay_type_value']==60)
selected='selected'
@endif>60</option>
<option value="90"
@if($payType['pay_type_value']==90)
selected='selected'
@endif>90</option>
</select>
</div>
&nbsp天
<input type="hidden" class="valueInput" name="pay_type_extra[]" value="天">
</div>
</div>
@else
<div class="pay_type_1_div" style="display: none">
<div class="layui-row" style="padding-left:70px">
<span class="require">*</span>月结 : &nbsp
<div class="layui-input-inline" style="width: 80px;">
<input class="layui-input valueInput" type="hidden" name="">
<select lay-filter="pay_type_month">
<option value="">请选择</option>
<option value="30">30</option>
<option value="60">60</option>
<option value="90">90</option>
</select>
</div>
&nbsp天
<input type="hidden" class="valueInput" name="" value="天">
</div>
</div>
@endif
@if ($payType['pay_type']==2)
<div class="pay_type_2_div">
<input type="hidden" class="valueInput" name="pay_type_value[]">
<input type="hidden" class="valueInput" name="pay_type_extra[]" value="">
</div>
@else
<div class="pay_type_2_div" style="display: none">
<input type="hidden" class="valueInput" name="">
<input type="hidden" class="valueInput" name="" value="">
</div>
@endif
@if ($payType['pay_type']==3)
<div class="pay_type_3_div">
<div class="layui-col-md3">
<label class="layui-form-label" style="margin-bottom: 5px">
<label class="layui-form-label">
<span class="require">*</span>首款要求 :
</label>
</div>
......@@ -62,47 +108,70 @@
</div>
<div class="layui-col-md6">
<div class="layui-input-inline" style="width: 100px;margin-left: -20px;">
<input class="layui-input" type="text" value="{{$payType['pay_type_value']}}" name="">
<input class="layui-input valueInput" type="text" name="pay_type_value[]"
value="{{$payType['pay_type_value']}}">
</div>
&nbsp
@if (!empty($payType['pay_type_extra'])&&strpos($payType['pay_type_extra'],'%')!==false)
<span class="temp">%</span>
<input type="hidden" class="valueInput" name="pay_type_extra[]" value="%">
@elseif (!empty($payType['pay_type_extra'])&&strpos($payType['pay_type_extra'],'RMB')!==false)
<span class="temp">RMB</span>
<input type="hidden" class="valueInput" name="pay_type_extra[]" value="RMB">
@else
<span class="temp">%</span>
<input type="hidden" class="valueInput" name="pay_type_extra[]"
value="%">
@endif
</div>
</div>
@else
<div class="pay_type_3_div" style="display: none">
<div class="layui-col-md3">
<label class="layui-form-label">
<span class="require">*</span>首款要求 :
</label>
</div>
<div class="layui-col-md3" style="margin-left: -15px">
<div class="layui-input-inline" style="width: 100px">
<select lay-filter="pay_type_3_type">
<option value="首款比例">首款比例</option>
<option value="首款金额">首款金额</option>
</select>
</div>
</div>
<div class="layui-col-md6">
<div class="layui-input-inline" style="width: 100px;margin-left: -20px;">
<input class="layui-input valueInput" type="text" name="">
</div>
&nbsp<span class="temp">%</span>
<input type="hidden" class="valueInput" name="" value="%">
</div>
</div>
@endif
{{-- <div style="float: left">--}}
{{-- <button type="button" class="layui-btn layui-btn-danger layui-btn-sm delete_pay_type">删除--}}
{{-- </button>--}}
{{-- <button type="button" class="layui-btn layui-btn-sm add_pay_type">新增</button>--}}
{{-- </div>--}}
</div>
</div>
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm delete_pay_type">删除</button>
</div>
@endforeach
@endif
</div>
<template id="pay_type_template">
<div class="layui-row pay_type_div" style="margin-bottom: 10px;">
<div class="layui-col-md2">
<div class="layui-row pay_type_div" style="margin-bottom: 5px;">
<div class="layui-col-md3">
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('pay_type[]','付款方式 : ',
isset($supplier['pay_type[]'])?$supplier['pay_type[]']:'',config('fixed.SupplierPayType'),['required'=>false]) !!}
</div>
</div>
<input type="hidden" name="pay_type_extra">
<input type="hidden">
<div class="layui-col-md10" style="width:500px;margin-bottom: 3px;">
<div class="layui-row">
<div class="pay_type_3_div" style="display: none">
<div class="layui-col-md3">
<label class="layui-form-label" style="margin-bottom: 5px">
<label class="layui-form-label">
<span class="require">*</span>首款要求 :
</label>
</div>
......@@ -116,28 +185,35 @@
</div>
<div class="layui-col-md6">
<div class="layui-input-inline" style="width: 100px;margin-left: -20px;">
<input class="layui-input" type="text" name="">
<input class="layui-input valueInput" type="text" name="pay_type_value[]">
</div>
&nbsp<span class="temp">%</span>
<input type="hidden" class="valueInput" name="pay_type_extra[]" value="%">
</div>
</div>
<div class="pay_type_1_div" style="display: none">
<div class="layui-row" style="padding-left:80px">
月结&nbsp
<div class="layui-input-inline" style="width: 50px;">
<input class="layui-input" type="text" name="">
<span class="require">*</span>月结 : &nbsp
<div class="layui-input-inline" style="width: 80px;">
<input class="layui-input valueInput" type="hidden" name="">
<select lay-filter="pay_type_month">
<option value="">请选择</option>
<option value="30">30</option>
<option value="60">60</option>
<option value="90">90</option>
</select>
</div>
&nbsp天
<input type="hidden" class="valueInput" name="" value="天">
</div>
</div>
<div class="pay_type_2_div" style="display: none">
</div>
<div style="float: left">
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm delete_pay_type">删除</button>
<button type="button" class="layui-btn layui-btn-sm add_pay_type">新增</button>
<input type="hidden" class="valueInput" name="">
<input type="hidden" class="valueInput" name="" value="">
</div>
</div>
</div>
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm delete_pay_type">删除</button>
</div>
</template>
......
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