Commit 77ff058c by 杨树贤

修复优化bug

parent f753797e
...@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command ...@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command
public function handle() public function handle()
{ {
$service = new DataService(); $service = new DataService();
$service->importSupplierLevel(); $service->makeTempTagForSupplier();
} }
} }
...@@ -288,17 +288,24 @@ class SupplierApiController extends Controller ...@@ -288,17 +288,24 @@ class SupplierApiController extends Controller
$supplierName = $request->get('supplier_name'); $supplierName = $request->get('supplier_name');
$supplierId = $request->get('supplier_id'); $supplierId = $request->get('supplier_id');
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$existedSupplierName = $model->where('supplier_name', $supplierName)->value('supplier_name');
//如果是编辑操作,则要忽略非当前 //如果是编辑操作,则要忽略非当前
if ($supplierId) { if ($supplierId) {
$originSupplierName = $model->where('supplier_id', $supplierId)->value('supplier_name');
$existedSupplierName = $model->where('supplier_name', $supplierName)->where('supplier_name','!=',$originSupplierName)
->value('supplier_name');
if ($supplierName !== $existedSupplierName) { if ($supplierName !== $existedSupplierName) {
$supplierName = $model->where('supplier_name', 'like', $supplierName = $model->where('supplier_name', 'like',
"%$supplierName%")->limit(1)->value('supplier_name'); "%$supplierName%")->limit(1)->value('supplier_name');
if (!empty($supplierName)) { if (!empty($supplierName)) {
$this->response(-2, '存在类似的供应商名称', $supplierName); $this->response(-2, '存在类似的供应商名称', $supplierName);
} }
}else{
$this->response(-1,'该供应商名称已经存在');
} }
} else { } else {
$existedSupplierName = $model->where('supplier_name', $supplierName)
->value('supplier_name');
if ($existedSupplierName) { if ($existedSupplierName) {
$this->response(-1, '已经有重复的供应商名称'); $this->response(-1, '已经有重复的供应商名称');
} else { } else {
......
...@@ -10,7 +10,6 @@ use App\Http\Validators\SupplierAttachmentValidator; ...@@ -10,7 +10,6 @@ use App\Http\Validators\SupplierAttachmentValidator;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierAttachmentModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class SupplierAttachmentApiController extends Controller class SupplierAttachmentApiController extends Controller
...@@ -34,7 +33,7 @@ class SupplierAttachmentApiController extends Controller ...@@ -34,7 +33,7 @@ class SupplierAttachmentApiController extends Controller
$this->response(0, 'ok', $list['data'], $list['total']); $this->response(0, 'ok', $list['data'], $list['total']);
} }
//获取供应商信息变更记录 //保存附件信息
public function SaveSupplierAttachment($request) public function SaveSupplierAttachment($request)
{ {
//先去表单验证 //先去表单验证
...@@ -58,6 +57,10 @@ class SupplierAttachmentApiController extends Controller ...@@ -58,6 +57,10 @@ class SupplierAttachmentApiController extends Controller
if (!$result) { if (!$result) {
$this->response(-1, '操作失败'); $this->response(-1, '操作失败');
} else { } else {
SupplierChannelModel::where('supplier_id', $attachment['supplier_id'])->update([
'update_time' => time(),
'status' => SupplierChannelModel::STATUS_PENDING,
]);
$logService = new LogService(); $logService = new LogService();
$content = !empty($attachment['attachment_id']) ? '修改附件信息' : '添加附件信息'; $content = !empty($attachment['attachment_id']) ? '修改附件信息' : '添加附件信息';
$remark = json_encode($attachment); $remark = json_encode($attachment);
......
...@@ -10,7 +10,6 @@ use App\Http\Services\ViewCheckService; ...@@ -10,7 +10,6 @@ use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel; use App\Model\IntracodeModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierAttachmentModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
......
...@@ -96,8 +96,6 @@ class SupplierController extends Controller ...@@ -96,8 +96,6 @@ class SupplierController extends Controller
]); ]);
$this->data['province_city'] = implode(' | ', $regionNames); $this->data['province_city'] = implode(' | ', $regionNames);
$this->data['address'] = $supplierService->getAddress($supplierId); $this->data['address'] = $supplierService->getAddress($supplierId);
$supplierAttachmentService = new SupplierAttachmentService();
$this->data['attachment'] = $supplierAttachmentService->getAttachment($supplierId);
return $this->view('供应商详情'); return $this->view('供应商详情');
} }
...@@ -180,8 +178,6 @@ class SupplierController extends Controller ...@@ -180,8 +178,6 @@ class SupplierController extends Controller
]); ]);
$this->data['supplier'] = $supplier; $this->data['supplier'] = $supplier;
$this->data['address'] = $supplierService->getAddress($supplierId); $this->data['address'] = $supplierService->getAddress($supplierId);
$supplierAttachmentService = new SupplierAttachmentService();
$this->data['attachment'] = $supplierAttachmentService->getAttachment($supplierId);
return $this->view('编辑供应商'); return $this->view('编辑供应商');
} }
......
...@@ -344,45 +344,6 @@ class DataService ...@@ -344,45 +344,6 @@ class DataService
} }
} }
//导入等级修改供应商并且找出没有等级的供应商(针对正式的)
public function importSupplierLevel()
{
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_level.xls';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]);
$level = trim($item[3]);
//先去判断是否存在
$exist = $supplierChannelModel->where('supplier_name', $supplierName)
->exists();
if (!$exist) {
$number++;
//然后修改excel
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('供应商不存在');
});
} else {
$supplierChannelModel->where('supplier_name', $supplierName)->update([
'level' => $level,
]);
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('修改成功');
});
}
}
var_dump("一共有${number}个不存在的供应商");
});
})->store('xls');
} catch (\Exception $exception) {
var_dump($exception);
}
}
//导入主营品牌数据 //导入主营品牌数据
public function importMainBrandData() public function importMainBrandData()
{ {
...@@ -472,43 +433,9 @@ class DataService ...@@ -472,43 +433,9 @@ class DataService
* 供应商0.5版本下面需要跑的数据方法 * 供应商0.5版本下面需要跑的数据方法
* */ * */
//转移付款方式到新添加的付款方式
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);
}
//临时供应商标记以及等级切换 //临时供应商标记以及等级切换
public function makeTempTagForSupplier() public function makeTempTagForSupplier($change = false)
{ {
/* /*
创建时间为2021-06-01开始截至现在,供应商类别为正式/临时,供应商性质为现货商,且没有上传品质协议,系统标签需要贴【临时供应商标签】,等级标记为E 创建时间为2021-06-01开始截至现在,供应商类别为正式/临时,供应商性质为现货商,且没有上传品质协议,系统标签需要贴【临时供应商标签】,等级标记为E
...@@ -532,12 +459,16 @@ class DataService ...@@ -532,12 +459,16 @@ class DataService
continue; continue;
} }
$newTags = $supplier['system_tags'] ? rtrim($supplier['system_tags'], ',') . ',临时供应商' : '临时供应商'; $newTags = $supplier['system_tags'] ? rtrim($supplier['system_tags'], ',') . ',临时供应商' : '临时供应商';
if ($tagService->saveTags($supplierId, 14, $newTags, $oldTags)) { echo "供应商编码 ${supplier['supplier_code']} 打上临时供应商标签,等级标记为E" . PHP_EOL;
SupplierChannelModel::where('supplier_id', $supplierId)->update([ if ($change) {
'system_tags' => $newTags, if ($tagService->saveTags($supplierId, 14, $newTags, $oldTags)) {
'level' => 'E' SupplierChannelModel::where('supplier_id', $supplierId)->update([
]); 'system_tags' => $newTags,
'level' => 'E'
]);
}
} }
} }
...@@ -693,8 +624,51 @@ class DataService ...@@ -693,8 +624,51 @@ class DataService
} }
} }
} }
}
//导入等级修改供应商并且找出没有等级的供应商(针对正式的)
public function importSupplierLevel($change = false)
{
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_level.xlsx';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($change) {
$supplierChannelModel = new SupplierChannelModel();
$reader->sheet('2021年评估', function ($sheet) use ($reader, $supplierChannelModel, $change) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]);
$level = trim($item[2]);
//先去判断是否存在
$exist = $supplierChannelModel->where('supplier_name', $supplierName)
->exists();
$levelExist = $supplierChannelModel->where('supplier_name', $supplierName)
->value('level');
if ($levelExist) {
echo "供应商 ${supplierName} 已有,等级为 : " . $level . PHP_EOL;
continue;
}
if (!$exist) {
$number++;
} else {
echo "修改供应商 ${supplierName} 等级为 : " . $level . PHP_EOL;
if ($change) {
$supplierChannelModel->where('supplier_name', $supplierName)->update([
'level' => $level,
]);
}
}
}
var_dump("一共有${number}个不存在的供应商");
});
});
} catch (\Exception $exception) {
dd($exception);
}
} }
} }
...@@ -5,10 +5,7 @@ namespace App\Http\Services; ...@@ -5,10 +5,7 @@ namespace App\Http\Services;
//后台用户相关信息服务 //后台用户相关信息服务
use App\Model\RedisModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use Illuminate\Support\Facades\DB;
//用于判断是否已经查看的服务 //用于判断是否已经查看的服务
class SupplierAttachmentService class SupplierAttachmentService
...@@ -16,16 +13,8 @@ class SupplierAttachmentService ...@@ -16,16 +13,8 @@ class SupplierAttachmentService
public function getAttachment($supplierId) public function getAttachment($supplierId)
{ {
$attachmentModel = new SupplierAttachmentModel(); $attachmentModel = new SupplierAttachmentsModel();
$attachmentData = $attachmentModel->where('supplier_id', $supplierId)->first(); return $attachmentModel->where('supplier_id', $supplierId)->get()->toArray();
$attachment = [];
if (!empty($attachmentData)) {
$attachment = json_decode($attachmentData, true);
$attachment = array_map(function ($item) {
return json_decode($item, true);
}, $attachment);
}
return $attachment;
} }
public function saveAttachment($attachment) public function saveAttachment($attachment)
......
...@@ -5,11 +5,8 @@ namespace App\Http\Services; ...@@ -5,11 +5,8 @@ namespace App\Http\Services;
use App\Http\Validators\SupplierValidator; use App\Http\Validators\SupplierValidator;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\RedisModel;
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
{ {
...@@ -203,7 +200,7 @@ class SupplierAuditService ...@@ -203,7 +200,7 @@ class SupplierAuditService
} }
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的 //判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
public function checkNeedAudit($supplierId, $channel, $attachment) public function checkNeedAudit($supplierId, $channel)
{ {
$notNeedAuditField = [ $notNeedAuditField = [
'register_company_name', 'register_company_name',
...@@ -229,16 +226,6 @@ class SupplierAuditService ...@@ -229,16 +226,6 @@ class SupplierAuditService
return true; return true;
} }
$attachmentModel = new SupplierAttachmentModel();
//判断附件有没有变化,有变化也要进入审核
$oldAttachment = $attachmentModel->select(array_keys(config('fixed.FileNameMapping')))
->where('supplier_id', $supplierId)->first();
$oldAttachment = !empty($oldAttachment) ? $oldAttachment->toArray() : [];
$newAttachment = $attachment;
if ($oldAttachment != $newAttachment) {
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) {
......
...@@ -9,7 +9,6 @@ use App\Http\Validators\SupplierValidator; ...@@ -9,7 +9,6 @@ use App\Http\Validators\SupplierValidator;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\RedisModel; use App\Model\RedisModel;
use App\Model\SupplierAddressModel; use App\Model\SupplierAddressModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
namespace App\Http\Validators; namespace App\Http\Validators;
use App\Http\Services\SupplierPayTypeService; use App\Http\Services\SupplierPayTypeService;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
......
...@@ -43,7 +43,7 @@ class SupplierChannelModel extends Model ...@@ -43,7 +43,7 @@ class SupplierChannelModel extends Model
//附件 //附件
public function attachment() public function attachment()
{ {
return $this->hasOne(SupplierAttachmentModel::class, 'supplier_id', 'supplier_id'); return $this->hasMany(SupplierAttachmentsModel::class, 'supplier_id', 'supplier_id');
} }
//交易方式 //交易方式
......
No preview for this file type
...@@ -192,26 +192,6 @@ ...@@ -192,26 +192,6 @@
{{-- <span class="required_field">*</span> 账期详情 :{{$supplier['billing_period_detail']}}--}} {{-- <span class="required_field">*</span> 账期详情 :{{$supplier['billing_period_detail']}}--}}
</div> </div>
</div> </div>
<div class="layui-row" style="width: 700px">
@if (!empty($attachment))
@foreach($attachment as $key=>$item)
@if(in_array($key,array_keys(config('fixed.FileNameMapping'))))
@if (!empty($item))
<div class="layui-col-md12">
@if ($key=='business_license')
<span class="required_field">*</span>
@endif
{{array_get(config('fixed.FileNameMapping'),$key)}} :
@foreach($item as $k=>$v)
<a href="{{array_get($v,'url')}}" style="color: dodgerblue"
target="_blank">{{array_get($v,'file_name','未知文件名')}}</a> |
@endforeach
</div>
@endif
@endif
@endforeach
@endif
</div>
<hr/> <hr/>
<blockquote class="layui-elem-quote layui-text"> <blockquote class="layui-elem-quote layui-text">
<b>系统设置</b> <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