Commit ac3c186e by 杨树贤

部分操作页面

parent daad5c05
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierContractService;
use App\Http\Transformers\SupplierContractTransformer;
use App\Model\SupplierContractModel;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
//获取供应商合同
class SupplierContractApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
//获取合同列表
public function GetSupplierContractList($request)
{
$supplierContractService = new SupplierContractService();
$data = $supplierContractService->getSupplierContractList($request);
$this->response(0, 'ok', $data['data'], $data['total']);
}
//新增合同
public function SaveSupplierContract($request)
{
$data = $request->only([
'id',
'contract_no',
'contract_file',
'supplier_id',
'status',
'commission_rate',
'start_date',
'end_date',
'check_date',
]);
$validator = \Validator::make($data, [
'supplier_id' => 'required|integer',
'start_date' => 'required|integer|min:1',
'end_date' => 'required|integer|min:1',
'commission_rate' => 'required|numeric',
'check_date' => 'required|integer|min:1'
], [
'supplier_id.required' => '供应商ID不能为空',
'supplier_id.integer' => '供应商ID必须为整数',
'start_date.required' => '合同开始时间不能为空',
'start_date.integer' => '合同开始时间必须为时间戳',
'start_date.min' => '合同开始时间必须为有效时间戳',
'end_date.required' => '合同结束时间不能为空',
'end_date.integer' => '合同结束时间必须为时间戳',
'end_date.min' => '合同结束时间必须为有效时间戳',
'commission_rate.required' => '抽佣比率不能为空',
'commission_rate.numeric' => '抽佣比率必须为数字',
'check_date.required' => '对账日期不能为空',
'check_date.integer' => '对账日期必须为时间戳',
'check_date.min' => '对账日期必须为有效时间戳'
]);
if ($validator->fails()) {
$this->response(-1, $validator->errors()->first());
}
$result = (new SupplierContractService())->saveSupplierContract($data);
if (!$result) {
$this->response(-1, '新增失败,请练习管理员');
}
$this->response(0, '新增成功');
}
/*
CREATE TABLE `supplier_contract` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`contract_no` varchar(50) DEFAULT '' COMMENT '合同编号',
`contract_file` varchar(255) DEFAULT '' COMMENT '合同文件路径',
`supplier_id` int(11) NOT NULL DEFAULT '0' COMMENT '供应商ID',
`status` tinyint(4) DEFAULT '1' COMMENT '状态 1:已生效 -1:已失效',
`commission_rate` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '抽佣比率',
`start_date` int(10) NOT NULL DEFAULT '0' COMMENT '合同开始时间',
`end_date` int(10) NOT NULL DEFAULT '0' COMMENT '合同结束时间',
`check_date` int(10) NOT NULL DEFAULT '0' COMMENT '对账日期',
`create_time` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
`create_uid` int(10) NOT NULL DEFAULT '0' COMMENT '创建人ID',
`create_name` varchar(50) NOT NULL DEFAULT '' COMMENT '创建人姓名',
`update_time` int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
`update_uid` int(10) NOT NULL DEFAULT '0' COMMENT '更新人ID',
`update_name` varchar(50) NOT NULL DEFAULT '' COMMENT '更新人姓名',
PRIMARY KEY (`id`),
KEY `idx_supplier_id` (`supplier_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='供应商合同表';
*/
//删除合同
public function deleteSupplierContract($request)
{
$id = $request->input('id');
$result = SupplierContractModel::where('id', $id)->delete();
if (!$result) {
$this->response(-1, '删除失败,请练习管理员');
}
$this->response(0, '删除成功');
}
//更新合同状态
public function UpdateSupplierContractStatus($request)
{
$data = $request->only(['id', 'status']);
$result = (new SupplierContractService())->updateSupplierContractStatus($data);
if (!$result) {
$this->response(-1, '更新失败,请联系管理员');
}
$this->response(0, '更新成功');
}
//获取合同日志
public function GetSupplierContractLogList($request)
{
$data = $request->only(['supplier_id', 'contract_id']);
$result = (new SupplierContractService())->getSupplierContractLogList($data);
$this->response(0, '获取成功', $result);
}
}
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierContractService;
use App\Http\Transformers\SupplierContractTransformer;
use App\Model\SupplierContractModel;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
//获取供应商合同
class SupplierContractApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
//获取合同列表
public function GetSupplierContractList($request)
{
$supplierContractService = new SupplierContractService();
$data = $supplierContractService->getSupplierContractList($request);
$this->response(0, 'ok', $data['data'], $data['total']);
}
//新增合同
public function SaveSupplierContract($request)
{
$data = $request->only([
'id',
'supplier_id',
'contract_number',
'contract_file',
'status',
'commission_rate',
'start_date',
'end_date',
'billing_date',
'updated_at',
'created_by',
'created_at'
]);
if (empty($data['contract_name'])) {
$this->response(-1, '合同名称不能为空');
}
if (strlen($data['contract_name']) > 30) {
$this->response(-1, '合同名称长度不能超过30个字符串');
}
if (empty(strip_tags($data['contract_file']))) {
$this->response(-1, '合同文件不能为空');
}
$result = (new SupplierContractService())->saveSupplierContract($data);
if (!$result) {
$this->response(-1, '新增失败,请联系管理员');
}
$this->response(0, '新增成功');
}
//删除合同
public function deleteSupplierContract($request)
{
$id = $request->input('id');
$result = SupplierContractModel::where('id', $id)->delete();
if (!$result) {
$this->response(-1, '删除失败,请练习管理员');
}
$this->response(0, '删除成功');
}
}
<?php
namespace App\Http\Controllers\Filter;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContractModel;
class SupplierContractFilter
{
//查询条件
public function listFilter($request)
{
$map = $request->all();
$model = new SupplierContractModel();
$query = $model->where('create_uid', $request->user->userId)->orderBy('id', 'desc');
if (!empty($map['supplier_code'])) {
$supplierId = SupplierChannelModel::where('supplier_code', $map['supplier_code'])->value('supplier_id');
$query->where('supplier_id', $supplierId);
}
if (!empty($map['status'])) {
$query->where('status', $map['status']);
}
if (!empty($map['create_time'])) {
$times = explode('~', $map['create_time']);
$startTime = strtotime($times[0]);
$endTime = strtotime($times[1]);
$query->whereBetween('create_time', [$startTime, $endTime]);
}
return $query;
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Model\IntracodeModel;
use App\Http\Services\RoleService;
use Illuminate\Support\Facades\DB;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContractModel;
use App\Http\Services\SupplierService;
use App\Http\Services\ViewCheckService;
use App\Http\Services\SupplierMemoService;
use App\Http\Services\SupplierContractService;
use App\Http\Services\SupplierStatisticsService;
class SupplierContractController extends Controller
{
public function info(Request $request, $id = '')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'user_email' => $request->user->email,
'uri' => '/' . $path,
'id' => $id
];
$userId = $request->user->userId;
$canAudit = perm($userId, 'AuditSupplier');
$this->data['canAudit'] = $canAudit;
//把是否是领导查看放到模板,用来区分部门老大能干的权限
$leaderView = perm($userId, 'LeaderView');
$this->data['leaderView'] = $leaderView;
return $this->$id($request);
}
public function __call($name, $arr)
{
$data['errinfo'] = '访问路径错误';
return view('errors.error', $data);
}
public function SaveSupplierContract($request)
{
$id = $request->get('id');
$supplierList = SupplierService::getSupplierCodeListForXmSelect();
if (!empty($id)) {
$model = new SupplierContractModel();
$this->data['contract'] = $model->where('id', $id)->first()->toArray();
}
$this->data['supplierList'] = $supplierList;
return $this->view('保存合同');
}
public function SupplierContractList($request)
{
$supplierList = SupplierService::getSupplierCodeListForXmSelect();
$this->data['supplierList'] = $supplierList;
return $this->view('合同列表');
}
}
<?php
namespace App\Http\Services;
use App\Model\LogModel;
use App\Model\SupplierLogModel;
use App\Model\SupplierExtendModel;
use App\Model\SupplierContractModel;
use App\Http\Services\LogService;
use App\Http\Transformers\SupplierContractTransformer;
use App\Http\Controllers\Filter\SupplierContractFilter;
class SupplierContractService
{
public function getSupplierContractList($request)
{
$limit = $request->get('limit', 10);
$filter = new SupplierContractFilter();
$query = $filter->listFilter($request);
$query->where('supplier_id', $request->input('supplier_id'));
$list = $query->paginate($limit)->toArray();
$transformer = new SupplierContractTransformer();
$list['data'] = $transformer->transformList($list['data']);
return $list;
}
//保存合同
public function saveSupplierContract($data)
{
try {
\DB::connection('web')->beginTransaction();
//记录日志
if (!empty($data['id'])) {
//修改时需要比对差异
$oldData = SupplierContractModel::where('id', $data['id'])->first();
if ($oldData) {
$diffArr = [];
$oldData = $oldData->toArray();
foreach ($data as $key => $value) {
if (isset($oldData[$key]) && $oldData[$key] != $value) {
$diffArr[] = $key . '由' . $oldData[$key] . '改为' . $value;
}
}
if (!empty($diffArr)) {
(new LogService())->addLog($data['supplier_id'], LogModel::UPDATE_OPERATE, '合同日志', '修改合同信息:' . implode(',', $diffArr));
}
}
} else {
//新增时记录一条日志
(new LogService())->addLog($data['supplier_id'], LogModel::ADD_OPERATE, '合同日志', '新增合同,合同编号:' . ($data['contract_no']), 1, request()->user->userId, request()->user->name);
}
if (empty($data['id'])) {
$data['create_time'] = time();
$data['create_uid'] = request()->user->userId;
$data['create_name'] = request()->user->name;
return SupplierContractModel::insert($data);
} else {
$data['update_time'] = time();
$data['update_uid'] = request()->user->userId;
$data['update_name'] = request()->user->name;
return SupplierContractModel::where('id', $data['id'])->update($data);
}
} catch (\Exception $e) {
\DB::connection('web')->rollBack();
return false;
}
}
//更新合同状态
public function updateSupplierContractStatus($data)
{
return SupplierContractModel::where('id', $data['id'])->update(['status' => $data['status']]);
}
//获取合同日志
public function getSupplierContractLogList($data)
{
return LogModel::where('supplier_id', $data['supplier_id'])->where('action', "合同日志")->orderBy('id', 'desc')->get();
}
}
<?php
namespace App\Http\Transformers;
class SupplierContractTransformer
{
public function transformList($list)
{
foreach ($list as &$contract) {
if (!$contract) {
continue;
}
$contract['create_time'] = $contract['create_time'] ? date(
'Y-m-d H:i:s',
$contract['create_time']
) : '';
$contract['update_time'] = $contract['update_time'] ? date(
'Y-m-d H:i:s',
$contract['update_time']
) : '';
}
unset($contract);
return $list;
}
}
...@@ -36,6 +36,7 @@ Route::group(['middleware' => ['web', 'menu']], function () { ...@@ -36,6 +36,7 @@ Route::group(['middleware' => ['web', 'menu']], function () {
Route::match(['get', 'post'], '/shipping_cost_ruler/{key}', 'ShippingCostRulerController@info'); Route::match(['get', 'post'], '/shipping_cost_ruler/{key}', 'ShippingCostRulerController@info');
Route::match(['get', 'post'], '/chain/{key}', 'ChainController@info'); Route::match(['get', 'post'], '/chain/{key}', 'ChainController@info');
Route::match(['get', 'post'], '/supplier_memo/{key}', 'SupplierMemoController@info'); Route::match(['get', 'post'], '/supplier_memo/{key}', 'SupplierMemoController@info');
Route::match(['get', 'post'], '/supplier_contract/{key}', 'SupplierContractController@info');
}); });
Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
...@@ -60,6 +61,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -60,6 +61,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/api/shipping_cost_ruler/{key}', 'ShippingCostRulerApiController@Entrance'); Route::match(['get', 'post'], '/api/shipping_cost_ruler/{key}', 'ShippingCostRulerApiController@Entrance');
Route::match(['get', 'post'], '/api/chain/{key}', 'ChainApiController@Entrance'); Route::match(['get', 'post'], '/api/chain/{key}', 'ChainApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_memo/{key}', 'SupplierMemoApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_memo/{key}', 'SupplierMemoApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_contract/{key}', 'SupplierContractApiController@Entrance');
//单独的统计接口 //单独的统计接口
Route::match(['get', 'post'], '/statisticsSkuNumber', function () { Route::match(['get', 'post'], '/statisticsSkuNumber', function () {
(new \App\Http\Services\DataService())->statisticsSkuNumberFromSKu(); (new \App\Http\Services\DataService())->statisticsSkuNumberFromSKu();
......
<?php
namespace App\Model;
use App\Model\SupplierChannelModel;
use Illuminate\Database\Eloquent\Model;
class SupplierContractModel extends Model
{
protected $connection = 'web';
protected $table = 'supplier_contract';
protected $primaryKey = 'id';
public $timestamps = false;
public function supplier()
{
return $this->belongsTo(SupplierChannelModel::class, 'supplier_id', 'supplier_id');
}
}
...@@ -343,5 +343,10 @@ return [ ...@@ -343,5 +343,10 @@ return [
2 => '采购已通过', 2 => '采购已通过',
3 => '采购未通过', 3 => '采购未通过',
4 => '采购未反馈', 4 => '采购未反馈',
] ],
'ContractStatus' => [
1 => '有效',
-1 => '失效',
],
]; ];
<script>
layui.use(['table', 'form', 'element', 'layer', 'admin', 'laydate', 'xmSelect'], function() {
let admin = layui.admin;
let form = layui.form;
let element = layui.element;
let laydate = layui.laydate;
let xmSelect = layui.xmSelect;
laydate.render({
elem: '#start_time',
type: 'datetime'
});
laydate.render({
elem: '#end_time',
type: 'datetime'
});
//初始化供应商编码下拉框
let supplierSelect = xmSelect.render({
el: '#supplier_id',
name: 'supplier_id',
data: {!! json_encode($supplierList) !!},
radio: true,
clickClose: true,
paging: true,
searchTips: '请输入要查找的供应商',
empty: '没有查找到数据',
autoRow: true,
pageSize: 30,
filterable: true,
height: "400px",
});
form.on('submit(load)', function(data) {
let url = '/api/supplier_contract/SaveSupplierContract';
let res = ajax(url, data.field);
if (!res) {
layer.msg('网络错误,请重试', {
icon: 6
});
} else {
if (res.err_code === 0) {
layer.msg('保存成功', {
icon: 6
});
setTimeout(function() {
admin.closeThisDialog();
}, 1000);
} else {
layer.msg(res.err_msg, {
icon: 5
});
}
}
return false;
});
});
</script>
<script>
layui.use(['table', 'form', 'element', 'layer', 'admin'], function () {
let admin = layui.admin;
let form = layui.form;
let element = layui.element;
$('#supplier_email').blur(function () {
let value = $(this).val();
if (value !== '') {
let reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
if (!reg.test(value)){
layer.msg('邮箱格式不对', {icon: 5});
}
}
});
form.on('submit(load)', function (data) {
let url = '/api/supplier_contact/SaveSupplierContact';
let res = ajax(url, data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
admin.putTempData("needFreshList", 1);
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
parent.layer.msg(res.err_msg, {icon: 5});
}
}
return false;
});
});
</script>
\ No newline at end of file
<style>
.layui-form-item {
margin-bottom: 5px;
}
.layui-input-suffix {
position: absolute;
right: 10px;
top: 0;
line-height: 38px;
}
</style>
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form" action="">
<input type="hidden" name="id" value="{{ $contract['id'] or '' }}">
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>合同编号</label>
<div class="layui-input-block block-42">
<input type="text" name="contract_no" id="contract_no" placeholder="请输入合同编号"
class="layui-input layui-disabled" value="{{ $contract['contract_no'] or '系统自动生成' }}" readonly>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>供应商</label>
<div class="layui-input-block block-42">
<div id="supplier_id" class="xm-select"></div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>合同有效期</label>
<div class="layui-input-inline" style="width: 150px;">
<input type="text" name="start_time" id="start_time" lay-verify="required" placeholder="开始日期"
class="layui-input" autocomplete="off">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width: 150px;">
<input type="text" name="end_time" id="end_time" lay-verify="required" placeholder="结束日期"
class="layui-input" autocomplete="off">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>抽佣比率</label>
<div class="layui-input-inline" style="position:relative">
<input type="number" name="commission_rate" id="commission_rate" placeholder="请输入抽佣比率"
class="layui-input" value="{{ $contract['commission_rate'] or '' }}">
<span class="layui-input-suffix">%</span>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>对账日期</label>
<div class="layui-input-inline">
<input type="number" name="check_date" id="check_date" min="1" max="31"
placeholder="请输入每月对账日期(1-31)" class="layui-input" value="{{ $contract['check_date'] or '' }}">
</div>
</div>
<div class="layui-form-item">
<div align="center" style="margin-top: 20px">
<button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="load">生成合同</button>
<button type="button" class="layui-btn layui-btn-primary" onclick="closeDialog()">取消</button>
</div>
</div>
</form>
</div>
</div>
<style>
.custom .layui-layer-content .table-status {
position: relative;
margin: 0 !important;
z-index: 2;
}
.custom .layui-layer-content .table-status th {
white-space: nowrap;
}
.layui-layer-content {
padding: 3px 3px !important;
}
.custom .layui-layer-content .table-status td,
.custom .layui-layer-content .table-status th {
padding: 3px 3px !important;
}
</style>
<div style="margin-left: 20px;margin-right: 20px">
<div class="layui-collapse" style="padding-top: 10px">
<form class="layui-form" action="">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">供应商:</label>
<div class="layui-input-inline">
<div id="supplier_id" class="xm-select"></div>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">状态:</label>
<div class="layui-input-inline">
<select name="status">
<option value="">全部</option>
@foreach (config('field.ContractStatus') as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div>
</div>
<div class="layui-inline">
<button class="layui-btn layui-btn-sm" lay-submit lay-filter="search">搜索</button>
<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
<div class="layui-btn-group demoTable" style="margin-top: 15px">
<button type="button" class="layui-btn layui-btn-sm" id="create_contract">生成寄售合同</button>
@if (checkPerm('EditContract'))
<button type="button" class="layui-btn layui-btn-sm" id="edit_contract">编辑</button>
@endif
</div>
<table class="layui-table" id="contractList" lay-filter="contractList"></table>
</div>
<script type="text/html" id="operateBar">
<div class="layui-btn-group">
@{{# if(d.status == 1){ }}
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="disable">失效</button>
@{{# }else{ }}
<button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="enable">生效</button>
@{{# } }}
<button type="button" class="layui-btn layui-btn-xs" lay-event="log">查看日志</button>
</div>
</script>
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