Commit b216f1a4 by 杨树贤

付款方式批量修改

parent 0c61f249
...@@ -79,7 +79,8 @@ class SupplierApiController extends Controller ...@@ -79,7 +79,8 @@ class SupplierApiController extends Controller
//付款方式 //付款方式
'pay_type', 'pay_type',
'pay_detail', 'pay_type_value',
'pay_type_extra'
]; ];
public function Entrance(Request $request, $id) public function Entrance(Request $request, $id)
...@@ -130,7 +131,7 @@ class SupplierApiController extends Controller ...@@ -130,7 +131,7 @@ class SupplierApiController extends Controller
} }
$channelMap = array_merge($this->channelMap, config('field.AttachmentFields')); $channelMap = array_merge($this->channelMap, config('field.AttachmentFields'));
$channel = $request->only($channelMap); $channel = $request->only($channelMap);
dd($channel); // dd($channel);
$service = new SupplierService(); $service = new SupplierService();
$result = $service->saveSupplier($channel); $result = $service->saveSupplier($channel);
if (!$result) { if (!$result) {
......
...@@ -12,6 +12,7 @@ use App\Model\StandardBrandModel; ...@@ -12,6 +12,7 @@ use App\Model\StandardBrandModel;
use App\Model\SupplierAttachmentModel; use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
...@@ -378,7 +379,7 @@ class DataService ...@@ -378,7 +379,7 @@ class DataService
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) { Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel(); $supplierChannelModel = new SupplierChannelModel();
$supplierService = new SupplierService(); $supplierService = new SupplierService();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel,$supplierService) { $reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel, $supplierService) {
$number = 0; $number = 0;
foreach ($reader->all()->toArray() as $key => $item) { foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]); $supplierName = trim($item[1]);
...@@ -415,6 +416,40 @@ class DataService ...@@ -415,6 +416,40 @@ class DataService
var_dump($exception); 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; ...@@ -8,6 +8,7 @@ use App\Model\RedisModel;
use App\Model\SupplierAttachmentModel; use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
class SupplierAuditService class SupplierAuditService
{ {
...@@ -170,7 +171,7 @@ class SupplierAuditService ...@@ -170,7 +171,7 @@ class SupplierAuditService
} }
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的 //判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
public function checkNeedAudit($supplierId, $channel, $attachment) public function checkNeedAudit($supplierId, $channel, $attachment, $payTypeData)
{ {
$notNeedAuditField = [ $notNeedAuditField = [
'register_company_name', 'register_company_name',
...@@ -200,6 +201,28 @@ class SupplierAuditService ...@@ -200,6 +201,28 @@ class SupplierAuditService
if ($oldAttachment != $newAttachment) { if ($oldAttachment != $newAttachment) {
return true; 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(); $supplier = $model->select($selectField)->where('supplier_id', $supplierId)->first()->toArray();
$changeField = []; $changeField = [];
foreach ($supplier as $key => $value) { foreach ($supplier as $key => $value) {
......
...@@ -8,10 +8,63 @@ use App\Model\SupplierPayTypeModel; ...@@ -8,10 +8,63 @@ use App\Model\SupplierPayTypeModel;
class SupplierPayTypeService 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) public static function getSupplierPayTypeList($supplierId)
{ {
$payTypeList = SupplierPayTypeModel::where('supplier_id', $supplierId)->get(); $payTypeList = SupplierPayTypeModel::where('supplier_id', $supplierId)->get();
$payTypeList = !empty($payTypeList) ? $payTypeList->toArray() : []; $payTypeList = !empty($payTypeList) ? $payTypeList->toArray() : [];
return $payTypeList; 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 ...@@ -71,16 +71,24 @@ class SupplierService
'hk' => $channel['hk'], 'hk' => $channel['hk'],
'cn' => $channel['cn'], 'cn' => $channel['cn'],
]; ];
unset($channel['hk'], $channel['cn']);
//获取收发货地有关的数据
$address = array_only($channel, $address = array_only($channel,
['supplier_id', 'shipping_address', 'return_address', 'return_consignee', 'return_phone']); ['supplier_id', 'shipping_address', 'return_address', 'return_consignee', 'return_phone']);
$shippingAddress = array_get($channel, 'shipping_address'); $shippingAddress = array_get($channel, 'shipping_address');
$attachment = $channel['attachment']; $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['return_consignee'], $channel['shipping_address'], $channel['cn_delivery_time_period'],
$channel['us_delivery_time_period'], $channel['attachment']); $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(); $skuAuditRulerService = new SupplierSkuAuditRulerService();
$channel['sku_audit_ruler'] = $skuAuditRulerService->getSkuAuditRulerForDB($channel['sku_audit_ruler']); $channel['sku_audit_ruler'] = $skuAuditRulerService->getSkuAuditRulerForDB($channel['sku_audit_ruler']);
$channel['pay_type'] = SupplierPayTypeService::getSupplierPayTypeForChannelDB($payTypeData);
//新增供应商操作 //新增供应商操作
if (empty($channel['supplier_id'])) { if (empty($channel['supplier_id'])) {
//先去插入到channel表 //先去插入到channel表
...@@ -98,7 +106,7 @@ class SupplierService ...@@ -98,7 +106,7 @@ class SupplierService
//判断是否是直接添加并且申请审核 //判断是否是直接添加并且申请审核
if (request()->get('direct_apply')) { if (request()->get('direct_apply')) {
$channel['status'] = SupplierChannelModel::STATUS_IN_REVIEW; $channel['status'] = SupplierChannelModel::STATUS_IN_REVIEW;
}else{ } else {
$channel['status'] = SupplierChannelModel::STATUS_PENDING; $channel['status'] = SupplierChannelModel::STATUS_PENDING;
} }
//第一次新增的供应商,都需要进行复审 //第一次新增的供应商,都需要进行复审
...@@ -117,13 +125,14 @@ class SupplierService ...@@ -117,13 +125,14 @@ class SupplierService
$channel = array_except($channel, $contactField); $channel = array_except($channel, $contactField);
$channel['channel_uid'] = $contact['can_check_uids']; $channel['channel_uid'] = $contact['can_check_uids'];
$supplierId = $this->newSupplierId = $model->insertGetId($channel); $supplierId = $this->newSupplierId = $model->insertGetId($channel);
//同时添加联系人 //同时添加联系人
$contact['supplier_id'] = $supplierId; $contact['supplier_id'] = $supplierId;
$contact['add_time'] = time(); $contact['add_time'] = time();
$contact['admin_id'] = request()->user->userId; $contact['admin_id'] = request()->user->userId;
$contactModel = new SupplierContactModel(); $contactModel = new SupplierContactModel();
$contactModel->insert($contact); $contactModel->insert($contact);
//保存生成的内部编码 //保存生成的内部编码
$this->saveSupplierCode($supplierId); $this->saveSupplierCode($supplierId);
//新增的时候也要去添加地址了 //新增的时候也要去添加地址了
...@@ -133,7 +142,7 @@ class SupplierService ...@@ -133,7 +142,7 @@ class SupplierService
$supplierId = $this->newSupplierId = $channel['supplier_id']; $supplierId = $this->newSupplierId = $channel['supplier_id'];
//要做进一步判断,部分字段修改不需要审核 //要做进一步判断,部分字段修改不需要审核
$auditService = new SupplierAuditService(); $auditService = new SupplierAuditService();
$needAudit = $auditService->checkNeedAudit($supplierId, $channel, $attachment); $needAudit = $auditService->checkNeedAudit($supplierId, $channel, $attachment,$payTypeData);
if ($needAudit) { if ($needAudit) {
$channel['status'] = SupplierChannelModel::STATUS_PENDING; $channel['status'] = SupplierChannelModel::STATUS_PENDING;
} }
...@@ -158,6 +167,8 @@ class SupplierService ...@@ -158,6 +167,8 @@ class SupplierService
$tagService->saveTags($supplierId, 14, $channel['system_tags'], $oldSystemTags); $tagService->saveTags($supplierId, 14, $channel['system_tags'], $oldSystemTags);
$tagService->saveTags($supplierId, 4, $channel['customer_tags'], $oldCustomerTags); $tagService->saveTags($supplierId, 4, $channel['customer_tags'], $oldCustomerTags);
} }
//保存付款方式列表
SupplierPayTypeService::saveSupplierPayTypeList($supplierId, $payTypeData);
//保存附件 //保存附件
$attachmentService = new SupplierAttachmentService(); $attachmentService = new SupplierAttachmentService();
$attachmentService->saveAttachment($supplierId, $attachment); $attachmentService->saveAttachment($supplierId, $attachment);
......
...@@ -101,7 +101,7 @@ class SupplierTransformer ...@@ -101,7 +101,7 @@ class SupplierTransformer
$supplier['region_name'] = array_get(config('fixed.Region'), $supplier['region']); $supplier['region_name'] = array_get(config('fixed.Region'), $supplier['region']);
$supplier['currency_name'] = array_get(config('fixed.Currency'), $supplier['currency']); $supplier['currency_name'] = array_get(config('fixed.Currency'), $supplier['currency']);
$supplier['supplier_group_name'] = array_get(config('fixed.SupplierGroup'), $supplier['supplier_group']); $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['trading_method_name'] = array_get(config('fixed.TradingMethod'), $supplier['trading_method']);
$supplier['main_brand_names'] = $this->getMainBrandNames($supplier['main_brands']); $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']) : ''; $supplier['update_time'] = $supplier['update_time'] ? date('Y-m-d H:i:s', $supplier['update_time']) : '';
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Http\Validators; namespace App\Http\Validators;
use App\Http\Services\SupplierPayTypeService;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
use Validator; use Validator;
...@@ -23,7 +24,6 @@ class SupplierValidator ...@@ -23,7 +24,6 @@ class SupplierValidator
'main_brands' => 'required', 'main_brands' => 'required',
'main_customers' => 'max:100', 'main_customers' => 'max:100',
'ticket_time' => 'max:20', 'ticket_time' => 'max:20',
// 'supplier_address' => 'required',
'region' => 'required', 'region' => 'required',
'cn_delivery_time' => 'regex:/^\d+\-\d$/', 'cn_delivery_time' => 'regex:/^\d+\-\d$/',
'us_delivery_time' => 'regex:/^\d+\-\d$/', 'us_delivery_time' => 'regex:/^\d+\-\d$/',
...@@ -32,8 +32,6 @@ class SupplierValidator ...@@ -32,8 +32,6 @@ class SupplierValidator
'return_address' => 'max:100', 'return_address' => 'max:100',
'return_consignee' => 'max:50', 'return_consignee' => 'max:50',
'return_phone' => 'max:50', 'return_phone' => 'max:50',
// 'business_license' => 'required',
// 'established_time' => 'required',
'cn_ratio' => 'min:1', 'cn_ratio' => 'min:1',
'us_ratio' => 'min:1', 'us_ratio' => 'min:1',
]; ];
...@@ -121,7 +119,21 @@ class SupplierValidator ...@@ -121,7 +119,21 @@ class SupplierValidator
if ($notCompleteContacts) { if ($notCompleteContacts) {
return "存在和你相关的联系人没有完善,请先去完善相关联系人"; 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 "请补充完整付款方式信息";
}
}
} }
}
} }
......
...@@ -46,8 +46,9 @@ Route::match(['get', 'post'], '/test', function () { ...@@ -46,8 +46,9 @@ Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService(); $service = new \App\Http\Services\DataService();
// $service->pushSupplierSKu(); // $service->pushSupplierSKu();
// $service->makeSupplierSystemTag(); // $service->makeSupplierSystemTag();
$service->importSupplier(); // $service->importSupplier();
// $service->transferFileData(); // $service->transferFileData();
$service->TransferPayTypeDataToNewTable();
// $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid(); // $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
// $service->replaceStandardBrandId(); // $service->replaceStandardBrandId();
}); });
...@@ -5,32 +5,48 @@ ...@@ -5,32 +5,48 @@
//要根据付款类型的不同选项,切换不同的显示 //要根据付款类型的不同选项,切换不同的显示
form.on('select(pay_type[])', function (data) { form.on('select(pay_type[])', function (data) {
const payType = data.value; 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') { if (payType === '1') {
$('.pay_type_2_div').hide(); parentDiv.find('.pay_type_2_div').hide();
$('.pay_type_3_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'); form.render('select');
} }
if (payType === '2') { if (payType === '2') {
$('.pay_type_1_div').hide(); parentDiv.find('.pay_type_1_div').hide();
$('.pay_type_3_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'); form.render('select');
} }
if (payType === '3') { if (payType === '3') {
$('.pay_type_1_div').hide(); parentDiv.find('.pay_type_1_div').hide();
$('.pay_type_2_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.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) { form.on('select(pay_type_3_type)', function (data) {
const value = data.value; const value = data.value;
let parentDiv = $(this).parents('.pay_type_3_div'); let parentDiv = $(this).parents('.pay_type_3_div');
if (value === '首款比例') { if (value === '首款比例') {
parentDiv.find('.temp').text('%') parentDiv.find('.temp').text('%')
parentDiv.find('.temp').next().val('%')
} }
if (value === '首款金额') { if (value === '首款金额') {
parentDiv.find('.temp').text('RMB') parentDiv.find('.temp').text('RMB')
parentDiv.find('.temp').next().val('RMB')
} }
}); });
...@@ -40,11 +56,19 @@ ...@@ -40,11 +56,19 @@
layer.msg('至少要保留一个付款方式', {icon: 5}); layer.msg('至少要保留一个付款方式', {icon: 5});
return; 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 () { $(document).on('click', '.add_pay_type', function () {
$('#pay_type_div_list').append($('#pay_type_template').html()); $('#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'); form.render('select');
}); });
......
...@@ -229,6 +229,10 @@ ...@@ -229,6 +229,10 @@
</div> </div>
<hr/> <hr/>
<blockquote class="layui-elem-quote layui-text"> <blockquote class="layui-elem-quote layui-text">
<b>付款方式</b>
</blockquote>
<hr/>
<blockquote class="layui-elem-quote layui-text">
<b>供应商标签</b> <b>供应商标签</b>
</blockquote> </blockquote>
<div class="layui-row"> <div class="layui-row">
......
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