Commit 1c64b640 by 杨树贤

增删改查逻辑

parent 734dceb1
......@@ -5,12 +5,9 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Services\PurchaseRemarkService;
use App\Http\Services\SupplierAuditService;
use App\Http\Transformers\PurchaseRemarkTransformer;
use App\Http\Validators\PurchaseRemarkValidator;
use App\Model\LogModel;
use App\Model\PurchaseRemarksModel;
use App\Model\SupplierChannelModel;
use App\Model\PurchaseRemarkModel;
use Illuminate\Http\Request;
class PurchaseRemarkApiController extends Controller
......@@ -25,9 +22,9 @@ class PurchaseRemarkApiController extends Controller
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new PurchaseRemarksModel();
$model = new PurchaseRemarkModel();
$model->where('supplier_id', $supplierId)->paginate();
$list = $model->where('supplier_id', $supplierId)->orderBy('attachment_id', 'desc')
$list = $model->where('supplier_id', $supplierId)->orderBy('id', 'desc')
->paginate($limit)->toArray();
$transformer = new PurchaseRemarkTransformer();
$list['data'] = $transformer->transformList($list['data']);
......@@ -37,73 +34,61 @@ class PurchaseRemarkApiController extends Controller
//保存附件信息
public function SavePurchaseRemark($request)
{
//先去表单验证
$validator = new PurchaseRemarkValidator();
$validateResult = $validator->checkSave($request);
if ($validateResult) {
$this->response(-1, $validateResult);
$id = $request->input('id');
$participateContent = $request->input('participate_content');
$startTime = $request->input('start_time');
$endTime = $request->input('end_time');
$supplierId = $request->input('supplier_id');
$remark = $request->input('remark');
if (!$supplierId) {
$this->response(-1,'供应商id不能为空');
}
$attachment = $request->only([
'field_name',
'validity_type',
'validity_period',
'description',
'file_name',
'file_url',
if (!$participateContent) {
$this->response(-1,'参与内容不能为空');
}
if (!$startTime || !$endTime) {
$this->response(-1,'开始和结束时间都不能为空');
}
if (!$remark) {
$this->response(-1,'备注内容不能为空');
}
$remark = $request->only([
'id',
'supplier_id',
'attachment_id',
'participate_content',
'start_time',
'end_time',
'description',
'remark',
]);
$attachmentService = new PurchaseRemarkService();
$supplierId = $attachmentService->saveAttachment($attachment);
if (!$supplierId) {
$remarkService = new PurchaseRemarkService();
$result = $remarkService->savePurchaseRemark($id,$remark);
if (!$result) {
$this->response(-1, '操作失败');
} else {
$canIgnoreAudit = (new SupplierAuditService())->checkCanIgnoreSupplierAudit($supplierId);
if (!$canIgnoreAudit) {
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => SupplierChannelModel::STATUS_PENDING,
]);
}
$logService = new LogService();
$content = !empty($attachment['attachment_id']) ? '修改附件信息' : '添加附件信息';
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
$content = !empty($remark['id']) ? '修改采购备注' : '添加采购备注';
$remark = json_encode($remark);
$logService->AddLog($remark['supplier_id'], LogModel::UPDATE_OPERATE, $content, $content, $remark);
$this->response(0, '保存成功');
}
}
//判断是否要进入审核中状态,因为部分字段修改是不需要走审核的
private function checkNeedAudit($oldAttachment, $newAttachment)
{
$notNeedAuditField = [
'remark',
];
$diff = array_diff($oldAttachment, $newAttachment);
unset($diff['update_time']);
$changeField = array_keys($diff);
foreach ($changeField as $filed) {
//只要有一个不存在于不需要审核的字段,就返回需要审核
if (!in_array($filed, $notNeedAuditField)) {
return true;
}
}
return false;
}
//删除
public function DeletePurchaseRemark($request)
{
$attachmentId = $request->get('attachment_id');
$model = new PurchaseRemarksModel();
$attachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
$result = $model->where('attachment_id', $attachmentId)->delete();
$id = $request->get('id');
$model = new PurchaseRemarkModel();
$remark = $model->where('id', $id)->first()->toArray();
$result = $model->where('id', $id)->delete();
if ($result) {
$logService = new LogService();
$content = "删除附件信息 : " . $attachment['type_name'];
$remark = json_encode($attachment);
$logService->AddLog($attachment['supplier_id'], LogModel::UPDATE_OPERATE, '删除附件信息', $content, $remark);
$content = "删除采购备注";
$logService->AddLog($remark['supplier_id'], LogModel::UPDATE_OPERATE, '删除采购备注', $content);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
......
......@@ -2,16 +2,8 @@
namespace App\Http\Controllers;
use App\Http\Services\RoleService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierStatisticsService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\PurchaseRemarkModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PurchaseRemarkController extends Controller
{
......@@ -42,29 +34,17 @@ class PurchaseRemarkController extends Controller
}
//供应商详情
public function AddPurchaseRemark($request)
//保存采购备注
public function SavePurchaseRemark($request)
{
$this->data['title'] = '添加附件';
return $this->view('添加附件');
}
//供应商详情
public function UpdatePurchaseRemark($request)
{
$attachmentId = $request->get('attachment_id');
if (!empty($attachmentId)) {
$model = new PurchaseRemarksModel();
$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;
$id = $request->get('id');
if (!empty($id)) {
$model = new PurchaseRemarkModel();
$remark = $model->where('id', $id)->first()->toArray();
$this->data['remark'] = $remark;
}
$this->data['title'] = '修改附件';
$this->data['view'] = 'AddPurchaseRemark';
return $this->view('修改附件');
$this->data['title'] = '保存采购备注';
$this->data['view'] = 'SavePurchaseRemark';
return $this->view('保存采购备注');
}
}
\ No newline at end of file
......@@ -4,44 +4,23 @@
namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\PurchaseRemarkModel;
//用于判断是否已经查看的服务
//采购备注服务
class PurchaseRemarkService
{
public function getPurchaseRemark($supplierId)
public function savePurchaseRemark($remarkId,$remark)
{
$remakeModel = new PurchaseRemarkModel();
return $remakeModel->where('supplier_id', $supplierId)->get()->toArray();
}
public function savePurchaseRemark($remake)
{
if ($remake['validity_period']) {
$validityPeriod = explode('~', $remake['validity_period']);
$remake['validity_start'] = strtotime(trim($validityPeriod[0]));
$remake['validity_end'] = strtotime(trim($validityPeriod[1]));
}
if ($remake['validity_type'] == 1) {
$remake['validity_start'] = $remake['validity_end'] = 0;
}
$remake['type_name'] = array_get(config('fixed.FileNameMapping'), $remake['field_name']);
unset($remake['validity_period']);
$remakeId = $remake['attachment_id'];
if (empty($remake['description'])) {
unset($remake['description']);
}
$remakeModel = new PurchaseRemarkModel();
if (empty($remakeId)) {
$remake['create_uid'] = request()->user->userId;
$remake['create_name'] = request()->user->name;
$remake['create_time'] = time();
return $remakeModel->insertGetId($remake);
$remarkModel = new PurchaseRemarkModel();
if (empty($remarkId)) {
$remark['create_uid'] = request()->user->userId;
$remark['create_name'] = request()->user->name;
$remark['create_time'] = time();
return $remarkModel->insertGetId($remark);
} else {
$remake['update_time'] = time();
return $remakeModel->where('attachment_id', $remakeId)->update($remake)?$remake['supplier_id']:0;
$remark['update_time'] = time();
return $remarkModel->where('id', $remarkId)->update($remark)?$remarkId:0;
}
}
......
......@@ -17,6 +17,7 @@ class PurchaseRemarkTransformer
if (!$remark) {
continue;
}
$remark['participate_type_name'] = array_get(config('field.PurchaseRemarkParticipateType'), $remark['participate_type'],'无');
$remark['create_time'] = $remark['create_time'] ? date('Y-m-d H:i:s',
$remark['create_time']) : '';
$remark['update_time'] = $remark['update_time'] ? date('Y-m-d H:i:s',
......
......@@ -30,6 +30,7 @@ Route::group(['middleware' => ['web', 'menu']], function () {
Route::match(['get', 'post'], '/sku/{key}', 'SkuController@Entrance');
Route::match(['get', 'post'], '/log/{key}', 'LogController@Entrance');
Route::match(['get', 'post'], '/supplier_apply/{key}', 'SupplierApplyController@info');
Route::match(['get', 'post'], '/purchase_remark/{key}', 'PurchaseRemarkController@info');
});
Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
......@@ -50,6 +51,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/api/supplier_examination/{key}', 'SupplierExaminationApiController@Entrance');
Route::match(['get', 'post'], '/api/sku_upload_log/{key}', 'SkuUploadLogApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_apply/{key}', 'SupplierApplyApiController@Entrance');
Route::match(['get', 'post'], '/api/purchase_remark/{key}', 'PurchaseRemarkApiController@Entrance');
//单独的统计接口
Route::match(['get', 'post'], '/statisticsSkuNumber', function () {
(new \App\Http\Services\DataService())->statisticsSkuNumber();
......
......@@ -249,4 +249,11 @@ return [
3 => 5,
0 => 5,
],
//采购备注参与类型
'PurchaseRemarkParticipateType' => [
1 => '全渠道参与',
2 => '型号',
3 => '品牌',
],
];
\ No newline at end of file
<script>
layui.use(['table', 'form', 'element', 'table', 'layer', 'admin', 'xmSelect'], function () {
let admin = layui.admin;
let form = layui.form;
let element = layui.element;
let xmSelect = layui.xmSelect;
form.on('submit(savePurchaseRemark)', function (data) {
let url = '/api/purchase_remark/SavePurchaseRemark';
let res = ajax(url, data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
parent.layer.msg(res.err_msg, {icon: 5});
}
}
return false;
});
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
form.on('submit(delete)', function (data) {
layer.confirm('确定要删除该条采购备注吗?', function (index) {
let id = data[0].id;
let res = ajax('/api/purchase_remark/DeletePurchaseRemark', {id: id})
if (res.err_code === 0) {
layer.msg(res.err_msg, {icon: 6})
setTimeout(function () {
admin.closeThisDialog();
},1000);
} else {
layer.msg(res.err_msg, {icon: 5})
}
});
});
});
</script>
\ No newline at end of file
......@@ -2,6 +2,7 @@
layui.use(['table', 'form', 'element', 'layer', 'admin', 'laydate', 'xmSelect'], function () {
let admin = layui.admin;
let form = layui.form;
let table = layui.table;
let layDate = layui.laydate;
let element = layui.element;
let xmSelect = layui.xmSelect;
......@@ -135,7 +136,7 @@
cols: [[
{field: 'participate_type_name', title: '参与类型', align: 'center', width: 140},
{field: 'participate_content', title: '传真', align: 'center', width: 140},
{field: 'duration', title: '开始时间 - 截至时间', align: 'center', width: 200},
{field: 'duration', title: '开始时间 - 截至时间', align: 'center', width: 300},
{field: 'remark', title: '备注内容', align: 'center'},
]],
id: 'purchaseRemarkList',
......@@ -143,11 +144,11 @@
});
//新增联系方式
$("#add_purchase_remark").click(function () {
$("#savePurchaserRemark").click(function () {
let supplierId = getQueryVariable('supplier_id');
layer.open({
type: 2,
content: '/purchase_remark/AddPurchaseRemark?view=iframe&supplier_id=' + supplierId,
content: '/purchase_remark/SavePurchaseRemark?view=iframe&supplier_id=' + supplierId,
area: ['600px', '525px'],
title: '新增采购备注',
end: function () { // 监听弹窗关闭
......
<style>
.layui-form-item {
margin-bottom: 5px;
}
</style>
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form" action="">
<div class="layui-form-item">
@inject('singleSelectPresenter','App\Presenters\SingleSelectPresenter')
{!! $singleSelectPresenter->render('participate_type','参与类型 :',!empty($remark)?$remark['participate_type']:1,config('field.PurchaseRemarkParticipateType'),['required'=>true]) !!}
</div>
<div class="layui-form-item">
<div align="center" style="margin-top: 20px">
<button type="button" class="layui-btn layui-btn-info submit-loading" lay-submit lay-filter="load">确认</button>
<button type="button" class="layui-btn layui-btn-primary" lay-filter="cancel">关闭</button>
<button type="button" class="layui-btn layui-btn-danger" lay-filter="delete">删除</button>
</div>
</div>
</form>
</div>
</div>
\ No newline at end of file
......@@ -68,7 +68,7 @@
<b>采购备注<span style="color: orange;margin-left: 10px">PS:设置后的备注信息,将会应用在【询报价系统】供销售看到;</span></b>
</blockquote>
<div class="layui-form-item">
<button class="layui-btn layui-btn-sm" id="addPurchaserRemark">添加备注</button>
<button class="layui-btn layui-btn-sm" type="button" id="savePurchaserRemark">添加备注</button>
<table class="layui-table" lay-filter="purchaseRemarkList" id="purchaseRemarkList"></table>
</div>
......@@ -76,28 +76,7 @@
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">商品总价不满</label>
<div class="layui-input-inline" style="width: 100px;">
<input class="layui-input" type="text" name="cn[max]" id="cn_max"
value="{{$supplier['extra_fee']['cn']['max'] or ''}}"
lay-verify="num">
</div>
<div class="layui-form-label" style="width: 100px;margin-left: -20px">元(人民币),收取</div>
<div class="layui-input-inline" style="width: 100px;">
<input class="layui-input" type="text" name="cn[price]"
value="{{$supplier['extra_fee']['cn']['price'] or ''}}"
lay-verify="float" value="">
</div>
<div class="layui-form-label" style="width: 40px;margin-left: -20px">元运费</div>
<div class="layui-input-inline" style="width: 100px;">
<input type="checkbox" title="全渠道收费" lay-skin="primary" lay-filter="cn_filter">
</div>
</div>
</div>
<div style="margin-bottom: 300px"></div>
<blockquote class="layui-elem-quote layui-text">
<b>采购附加费设置</b>
......@@ -142,7 +121,6 @@
</div>
</div>
</div>
<blockquote class="layui-elem-quote layui-text">
<b>采购价格系数调整</b>
</blockquote>
......
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