Commit 20d7ccda by 杨树贤

运费规则

parent 87b52648
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Services\ShippingCostRulerService;
use App\Http\Transformers\ShippingCostRulerTransformer;
use App\Model\LogModel;
use App\Model\ShippingCostRulerModel;
use Illuminate\Http\Request;
class ShippingCostRulerApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
public function GetShippingCostRulerList($request)
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new ShippingCostRulerModel();
$model->where('supplier_id', $supplierId)->paginate();
$list = $model->where('supplier_id', $supplierId)->orderBy('id', 'desc')
->paginate($limit)->toArray();
$transformer = new ShippingCostRulerTransformer();
$list['data'] = $transformer->transformList($list['data']);
$this->response(0, 'ok', $list['data'], $list['total']);
}
public function SaveShippingCostRuler($request)
{
$id = $request->input('id');
$currency = $request->input('currency');
$orderAmount = $request->input('order_amount');
$shippingCost = $request->input('shipping_cost');
$supplierId = $request->input('supplier_id');
$rulerText = $request->input('ruler_text');
if (!$supplierId) {
$this->response(-1,'供应商id不能为空');
}
if (!$currency) {
$this->response(-1,'订单币种不能为空');
}
if (!$orderAmount) {
$this->response(-1,'单笔订单金额不能为空');
}
$ruler = $request->only([
'id',
'supplier_id',
'order_amount',
'shipping_cost',
'currency',
'ruler_text',
]);
$rulerService = new ShippingCostRulerService();
$result = $rulerService->saveShippingCostRuler($id,$ruler);
if (!$result) {
$this->response(-1, '操作失败');
} else {
$logService = new LogService();
$content = !empty($ruler['id']) ? '修改运费规则' : '添加运费规则';
$supplierId = $ruler['supplier_id'];
$ruler = json_encode($ruler);
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, $content, $content, $ruler);
$this->response(0, '保存成功');
}
}
public function DeleteShippingCostRuler($request)
{
$id = $request->get('id');
$model = new ShippingCostRulerModel();
$ruler = $model->where('id', $id)->first()->toArray();
$result = $model->where('id', $id)->delete();
if ($result) {
$logService = new LogService();
$content = "删除运费规则";
$logService->AddLog($ruler['supplier_id'], LogModel::UPDATE_OPERATE, '删除运费规则', $content);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\ShippingCostRulerModel;
use Illuminate\Http\Request;
class ShippingCostRulerController 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,
];
return $this->$id($request);
}
}
public function __call($name, $arr)
{
$data['errinfo'] = '访问路径错误';
return view('errors.error', $data);
}
//保存采购备注
public function SaveShippingCostRuler($request)
{
$id = $request->get('id');
if (!empty($id)) {
$model = new ShippingCostRulerModel();
$ruler = $model->where('id', $id)->first()->toArray();
$this->data['ruler'] = $ruler;
}
$this->data['title'] = '保存采购备注';
$this->data['view'] = 'SaveShippingCostRuler';
return $this->view('保存采购备注');
}
}
\ No newline at end of file
<?php
namespace App\Http\Services;
use App\Model\ShippingCostRulerModel;
//采购备注服务
class ShippingCostRulerService
{
public function saveShippingCostRuler($remarkId,$remark)
{
$remarkModel = new ShippingCostRulerModel();
if (empty($remarkId)) {
$remark['create_uid'] = request()->user->userId;
$remark['create_name'] = request()->user->name;
$remark['create_time'] = time();
return $remarkModel->insertGetId($remark);
} else {
$remark['update_time'] = time();
return $remarkModel->where('id', $remarkId)->update($remark)?$remarkId:0;
}
}
}
\ No newline at end of file
<?php
namespace App\Http\Transformers;
class ShippingCostRulerTransformer
{
public function transformList($list)
{
if (empty($list)) {
return [];
}
foreach ($list as &$remark) {
if (!$remark) {
continue;
}
$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',
$remark['update_time']) : '';
}
unset($remark);
return $list;
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ShippingCostRulerModel extends Model
{
protected $connection='web';
protected $table='shipping_cost_ruler';
protected $primaryKey = 'id';
public $timestamps = false;
}
<?php
namespace App\Presenters;
use App\Http\Services\StandardBrandService;
class StandardBrandNameListPresenter
{
public function render($name, $fieldText, $value = null, $option = [])
{
//因为这个组件是专门给标准品牌用的,所以可以直接去获取标准列表展示出来
$standardBrandNameList = '';
if ($value) {
$standardBrandNameList = (new StandardBrandService())->getStandardBrandNameListByBrandIds($value);
}
$isRequired = \Arr::get($option, 'required', false);
$requiredHtml = $isRequired ? '<span style="color: red;margin-right: 3px">*</span>' : '';
$html = <<<EOF
<label class="layui-form-label">
$requiredHtml $fieldText</label>
<div class="layui-input-block" style="width: 80%">
<input type="hidden" name="$name" value="$value" id="$name">
<div class="layui-col-md7">
<textarea rows="7" placeholder="标准品牌名称,多个用英文逗号隔开" class="layui-textarea" id="${name}_name_list">$standardBrandNameList</textarea>
<blockquote class="layui-elem-quote" id="valid_${name}_name_list">$standardBrandNameList</blockquote>
<span style="color: red" id="invalid_${name}_name_list"></span>
</div>
<div class="layui-col-md5">
<button type="button" class="layui-btn-sm layui-btn" id="check_and_add_${name}_name_list" style="margin-left: 10px;">验证并加入</button>
<p style="margin-top: 130px;margin-left: 10px"></p>
</div>
</div>
<script>
$(document).on('click','#check_and_add_${name}_name_list',function () {
let standardBrandNameList = $('#${name}_name_list').val();
let url = '/api/commonData/checkStandardBrandNameList';
layer.load();
var self = $(this);
$.ajax({
url: url,
type: 'POST',
async: true,
data: {
standard_brand_name_list: standardBrandNameList
},
dataType: 'json',
timeout: 20000,
success: function (res) {
let brandCount = 0;
layer.closeAll();
if (res.code === 0) {
//得到结果后还要操作div
let data = res.data;
let invalidBrandNameList = data.invalid_brand_name_list;
let validBrandIds = data.valid_brand_ids;
let validBrandNameList = data.valid_brand_name_list;
let standardBrandIds = $('#${name}').val();
standardBrandIds = standardBrandIds.split(',');
standardBrandIds = validBrandIds;
standardBrandIds = array_unique(array_remove_empty(standardBrandIds));
$('#${name}').val(standardBrandIds.join(','));
// let validStandardBrandNameList = $('#valid_${name}_name_list').text();
// validStandardBrandNameList = validStandardBrandNameList.split(',');
let validStandardBrandNameList = validBrandNameList;
validStandardBrandNameList = array_unique(array_remove_empty(validStandardBrandNameList));
brandCount = validStandardBrandNameList.length;
$('#valid_${name}_name_list').text(validStandardBrandNameList.join(','));
// $('#${name}_name_list').val(validStandardBrandNameList.join(','));
// let invalidStandardBrandNameList = $('#invalid_${name}_name_list').val();
// let invalidStandardBrandNameList = '';
// invalidStandardBrandNameList = invalidStandardBrandNameList.split(',');
// invalidStandardBrandNameList = $.merge(invalidStandardBrandNameList, invalidBrandNameList);
$('#invalid_${name}_name_list').text('');
let invalidStandardBrandNameList = invalidBrandNameList;
invalidStandardBrandNameList = array_unique(array_remove_empty(invalidStandardBrandNameList));
if (invalidStandardBrandNameList.length > 0){
let text = '品牌名称 : ' + invalidStandardBrandNameList.join('、') + ' 未匹配到标准品牌';
$('#invalid_${name}_name_list').text(text);
$('#invalid_${name}_name_list').val(invalidStandardBrandNameList.join('、'));
}
self.next().text(brandCount+'个');
} else {
layer.msg(res.msg, {icon: 5});
}
},
error: function () {
layer.closeAll();
layer.msg('网络错误', {icon: 5});
}
});
});
</script>
EOF;
return $html;
}
}
\ No newline at end of file
...@@ -256,4 +256,15 @@ return [ ...@@ -256,4 +256,15 @@ return [
2 => '型号', 2 => '型号',
3 => '品牌', 3 => '品牌',
], ],
//运费规则币种
'ShippingCostRulerCurrency' => [
1 => '人民币(RMB)',
2 => '美金(USD)'
],
//运费规则条件
'ShippingCostRulerCondition' => [
1 => '小于',
2 => '大于等于'
],
]; ];
\ No newline at end of file
<script>
layui.use(['table', 'form', 'element', 'table', 'layer', 'admin', 'xmSelect', 'laydate'], 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'
, format: 'yyyy-MM-dd'
});
laydate.render({
elem: '#end_time'
, format: 'yyyy-MM-dd'
});
function setConditionCurrencyName(currency) {
if (currency == 1) {
$('#ruler_condition_center_text').text('元(RMB),收取运费');
$('#ruler_condition_end_text').text('元(RMB)');
} else {
$('#ruler_condition_center_text').text('美元(USD),收取运费');
$('#ruler_condition_end_text').text('美元(USD)');
}
}
let currency = $('#currency').val();
setConditionCurrencyName(currency);
form.on('radio(currency)', function (data) {
currency = data.value;
setConditionCurrencyName(data.value);
setRulerText();
});
function setRulerText(){
let condition = $('#condition').val();
let conditionName = condition == 1 ? '小于' : '大于等于';
//订单金额小于¥100.00,收取运费¥5.00;
let rulerText = '';
let orderAmountFormat;
let shippingCostFormat;
let orderAmount = $('#order_amount').val();
if (orderAmount) {
orderAmountFormat = currency == 1 ? '¥' + orderAmount : '$' + orderAmount;
}
let shippingCost = $('#shipping_cost').val();
if (shippingCost) {
shippingCost = parseInt(shippingCost);
shippingCostFormat = currency == 1 ? '¥' + shippingCost.toFixed(2) : '$' + shippingCost.toFixed(2);
}
if (orderAmount) {
if (shippingCost == 0) {
rulerText = "订单金额" + conditionName + orderAmountFormat + ",包邮;";
} else {
rulerText = "订单金额" + conditionName + orderAmountFormat + ",收取运费" + shippingCostFormat + ";";
}
}
console.log(rulerText);
$('#ruler_text').val(rulerText);
}
$('#order_amount,#shipping_cost').on('input', function () {
setRulerText();
});
form.on('submit(saveShippingCostRuler)', function (data) {
let url = '/api/shipping_cost_ruler/SaveShippingCostRuler';
data.field.supplier_id = getQueryVariable('supplier_id');
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();
});
});
</script>
\ No newline at end of file
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
last: false,//不显示尾页 last: false,//不显示尾页
cols: [[ cols: [[
{field: 'operate', title: '操作', fixed: 'left', width: 130, templet: '#operate'}, {field: 'operate', title: '操作', fixed: 'left', width: 130, templet: '#operate'},
{field: 'participate_type_name', title: '参与类型', align: 'center', width: 140},
{ {
field: 'status', title: '状态', align: 'center', width: 80, templet: function (data) { field: 'status', title: '状态', width: 80, templet: function (data) {
return data.status == 1 ? "<span style='color: red'>停用</span>" : '启用'; return data.status == 1 ? "<span style='color: red'>停用</span>" : '启用';
} }
}, },
{field: 'duration', title: '开始时间 - 截至时间', align: 'center', width: 250}, {field: 'participate_type_name', title: '参与类型', width: 140},
{field: 'remark', title: '备注内容', align: 'center'}, {field: 'duration', title: '开始时间 - 截至时间', width: 250},
{field: 'remark', title: '备注内容',},
]], ]],
id: 'purchaseRemarkList', id: 'purchaseRemarkList',
page: {}, page: {},
...@@ -105,14 +105,8 @@ ...@@ -105,14 +105,8 @@
last: false,//不显示尾页 last: false,//不显示尾页
cols: [[ cols: [[
{field: 'operate', title: '操作', fixed: 'left', width: 130, templet: '#operate'}, {field: 'operate', title: '操作', fixed: 'left', width: 130, templet: '#operate'},
{field: 'participate_type_name', title: '参与类型', align: 'center', width: 140}, {field: 'id', title: '规则', width: 80},
{ {field: 'ruler_text', title: '内容',},
field: 'status', title: '状态', align: 'center', width: 80, templet: function (data) {
return data.status == 1 ? "<span style='color: red'>停用</span>" : '启用';
}
},
{field: 'duration', title: '开始时间 - 截至时间', align: 'center', width: 250},
{field: 'remark', title: '备注内容', align: 'center'},
]], ]],
id: 'shippingCostRulerList', id: 'shippingCostRulerList',
page: {}, page: {},
...@@ -124,8 +118,8 @@ ...@@ -124,8 +118,8 @@
layer.open({ layer.open({
type: 2, type: 2,
content: '/shipping_cost_ruler/SaveShippingCostRuler?view=iframe&supplier_id=' + supplierId, content: '/shipping_cost_ruler/SaveShippingCostRuler?view=iframe&supplier_id=' + supplierId,
area: ['800px', '725px'], area: ['800px', '425px'],
title: '新增采购备注', title: '添加运费规则',
end: function () { // 监听弹窗关闭 end: function () { // 监听弹窗关闭
table.reload('shippingCostRulerList'); table.reload('shippingCostRulerList');
} }
...@@ -139,7 +133,7 @@ ...@@ -139,7 +133,7 @@
if (layEvent === 'edit') { if (layEvent === 'edit') {
layer.open({ layer.open({
type: 2, type: 2,
area: ['800px', '725px'], area: ['800px', '425px'],
fixed: false, fixed: false,
offset: '50px', offset: '50px',
//不固定 //不固定
......
<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('currency','订单币种 :',!empty($ruler)?$ruler['currency']:1,config('field.ShippingCostRulerCurrency'),['required'=>true]) !!}
</div>
<div class="layui-form-item" >
<label class="layui-form-label"><span style="color: red">*</span>单笔订单金额</label>
<div class="layui-input-block" style="max-height: 30px">
<div class="layui-col-xs2">
<select name="condition" value="{{$ruler['condition'] or 1}}">
@foreach(config('field.ShippingCostRulerCondition') as $key => $name)
<option value="{{$key}}"
@if(!empty($ruler)&&$ruler['condition']==$key) checked @endif
>{{$name}}</option>
@endforeach
</select>
</div>
<div class="layui-col-xs2">
<input class="layui-input" name="order_amount" id="order_amount" value="{{$ruler['order_amount'] or 0}}">
</div>
<div class="layui-col-xs3" style="padding-left: 10px">
<span id="ruler_condition_center_text">
元(RMB),收取运费
</span>
</div>
<div class="layui-col-xs2">
<input class="layui-input" name="shipping_cost" id="shipping_cost" value="{{$ruler['shipping_cost'] or 0}}">
</div>
<div class="layui-col-xs3" style="padding-left: 10px">
<span id="ruler_condition_end_text">
元(RMB)
</span>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">规则预览 : </label>
<div class="layui-input-block">
<textarea rows="1" name="ruler_text" placeholder=""
class="layui-textarea layui-disabled" disabled
id="ruler_text">{{$ruler['ruler_text'] or ''}}</textarea>
</div>
</div>
<div class="layui-form-item">
<div align="right" style="margin-top: 20px">
<button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
lay-filter="saveShippingCostRuler">确认
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
lay-filter="cancel">关闭
</button>
</div>
</div>
</form>
</div>
</div>
\ No newline at end of file
<blockquote class="layui-elem-quote layui-text"> <blockquote class="layui-elem-quote layui-text">
<b>采购备注<span <b>运费设置-国际运费<span style="color: orange;margin-left: 10px">PS:设置后的运费规则,将会应用在【询报价系统】供销售看到(仅做为提示)</span></b>
style="color: orange;margin-left: 10px">PS:设置后的备注信息,将会应用在【询报价系统】供销售看到(仅做为提示)</span></b>
</blockquote> </blockquote>
{{--运费规则--}} {{--运费规则--}}
...@@ -9,6 +8,12 @@ ...@@ -9,6 +8,12 @@
<table class="layui-table" lay-filter="shippingCostRulerList" id="shippingCostRulerList"></table> <table class="layui-table" lay-filter="shippingCostRulerList" id="shippingCostRulerList"></table>
</div> </div>
<blockquote class="layui-elem-quote layui-text">
<b>采购备注<span
style="color: orange;margin-left: 10px">PS:设置后的备注信息,将会应用在【询报价系统】供销售看到(仅做为提示)</span></b>
</blockquote>
{{--采购备注--}} {{--采购备注--}}
<div class="layui-form-item"> <div class="layui-form-item">
<button class="layui-btn layui-btn-sm" type="button" id="savePurchaserRemark">添加备注</button> <button class="layui-btn layui-btn-sm" type="button" id="savePurchaserRemark">添加备注</button>
......
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