shop端添加商品返比设置

This commit is contained in:
wangxiaowei 2024-11-16 15:05:43 +08:00
parent 18a2ec33dc
commit 41363bacd0
7 changed files with 261 additions and 59 deletions

@ -6,5 +6,37 @@ use app\common\basics\Models;
class GoodsSubsidy extends Models
{
public function getSubsidy($get)
{
$lists = $this->where('is_delete', 0)
->order('id desc')
->field('id, profit, discount, subsidy')
->paginate([
'list_rows'=> $get['limit'],
'page'=> $get['page'],
]);
foreach ($lists as &$v) {
$v['profit'] = self::formatStr($v['profit']);
$v['discount'] = self::formatStr($v['discount']);
$v['subsidy'] = self::formatStr($v['subsidy']);
}
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
}
public function getSubsidyById($id)
{
$result = $this->where(['id' => $id, 'is_delete' => 0])->field('id, profit, discount, subsidy')->find();
$result['profit'] = self::formatStr($result['profit']);
$result['discount'] = self::formatStr($result['discount']);
$result['subsidy'] = self::formatStr($result['subsidy']);
return $result;
}
private static function formatStr($str)
{
$s = explode('.', $str);
return $s[1] > 0 ? $s . '%' : intval($str) . '%';
}
}

@ -21,27 +21,26 @@
namespace app\shop\controller\goods;
use app\admin\logic\goods\CategoryLogic as MallCategoryLogic;
use app\common\basics\ShopBase;
use app\common\enum\GoodsEnum;
use app\common\model\goods\GoodsBrand;
use app\common\model\goods\GoodsUnit;
use app\common\model\goods\GoodsCategory;
use app\common\model\Freight;
use app\common\model\goods\Supplier;
use app\common\model\goods\Goods as GoodsModel;
use app\common\logic\CommonLogic;
use app\common\model\Freight;
use app\common\model\goods\Goods as GoodsModel;
use app\common\model\goods\GoodsBrand;
use app\common\model\goods\GoodsCategory;
use app\common\model\goods\GoodsUnit;
use app\common\model\goods\Supplier;
use app\common\server\ArrayServer;
use app\common\server\JsonServer;
use app\shop\logic\goods\CategoryLogic as ShopCategoryLogic;
use app\shop\logic\goods\GoodsLogic;
use app\shop\validate\goods\GoodsMoreSpec;
use app\shop\validate\goods\GoodsMoreSpecLists;
use app\shop\validate\goods\GoodsOneSpec;
use app\shop\validate\goods\GoodsStatusValidate;
use app\shop\validate\goods\GoodsValidate;
use app\admin\logic\goods\CategoryLogic as MallCategoryLogic;
use app\shop\logic\goods\CategoryLogic as ShopCategoryLogic;
use app\common\model\goods\GoodsSubsidy;
/**
* 商品管理
@ -65,11 +64,11 @@ class Goods extends ShopBase
$shop_cate_list = ShopCategoryLogic::listAll($this->shop_id);
$statistics = GoodsLogic::statistics($this->shop_id);
return view('', [
'statistics' => $statistics,
'cate_list' => $cate_list, //平台分类
'shop_cate_list' => $shop_cate_list, //商家分类
'goods_type' => GoodsEnum::getTypeDesc(),
'shop_type' => session('shop_info')['type'] ?? 2
'statistics' => $statistics,
'cate_list' => $cate_list, //平台分类
'shop_cate_list' => $shop_cate_list, //商家分类
'goods_type' => GoodsEnum::getTypeDesc(),
'shop_type' => session('shop_info')['type'] ?? 2
]);
}
@ -105,11 +104,11 @@ class Goods extends ShopBase
unset($spec_lists['spec_values']);
unset($spec_lists['spec_value_ids']);
unset($spec_lists['delivery_type']);
unset($spec_lists['c_name']);
unset($spec_lists['c_name']);
unset($spec_lists['c_phone']);
unset($spec_lists['work_remark']);
unset($spec_lists['goods_remark']);
unset($spec_lists['first_cate_id']);
unset($spec_lists['first_cate_id']);
unset($spec_lists['second_cate_id']);
unset($spec_lists['third_cate_id']);
$goods_number = $spec_lists['goods_number'];
@ -144,17 +143,17 @@ class Goods extends ShopBase
}
}
// 添加商品
$result = GoodsLogic::add($this->shop_id, $post, $spec_lists,$goods_number,$w_discount,$purchase_content,$purchase_child_price);
// 添加商品
$result = GoodsLogic::add($this->shop_id, $post, $spec_lists, $goods_number, $w_discount, $purchase_content, $purchase_child_price);
if (true !== $result) {
return JsonServer::error(GoodsLogic::getError() ?: '操作失败');
}
return JsonServer::success('添加成功');
}
$a = MallCategoryLogic::getAllTree();
$a = MallCategoryLogic::getAllTree();
return view('', [
'category_lists_new' => $a,
'category_lists_new' => $a,
'category_first' => "",
'category_second' => "",
'second_pid' => "",
@ -208,11 +207,11 @@ class Goods extends ShopBase
unset($spec_lists['spec_id']);
unset($spec_lists['spec_value_ids']);
unset($spec_lists['delivery_type']);
unset($spec_lists['c_name']);
unset($spec_lists['c_name']);
unset($spec_lists['c_phone']);
unset($spec_lists['goods_remark']);
unset($spec_lists['work_remark']);
unset($spec_lists['first_cate_id']);
unset($spec_lists['work_remark']);
unset($spec_lists['first_cate_id']);
unset($spec_lists['second_cate_id']);
unset($spec_lists['third_cate_id']);
$goods_number = $spec_lists['goods_number'];
@ -245,7 +244,7 @@ class Goods extends ShopBase
return JsonServer::error('至少有一个规格的库存大于0');
}
}
$result = GoodsLogic::edit($post, $spec_lists,$goods_number,$w_discount,$purchase_content,$purchase_child_price);
$result = GoodsLogic::edit($post, $spec_lists, $goods_number, $w_discount, $purchase_content, $purchase_child_price);
if (true !== $result) {
return JsonServer::error(GoodsLogic::getError() ?: '操作失败');
}
@ -254,33 +253,37 @@ class Goods extends ShopBase
$goods_id = $this->request->get('goods_id');
$a = MallCategoryLogic::getAllTree();
$b = GoodsLogic::info($goods_id);
$second_pid = array();
$arr = $arr1 = array();
if($b['base']['second_cate_id']!=0){
$second_pid = GoodsCategory::where("id in (".$b['base']['second_cate_id'].")")->select();
if(!empty($second_pid)){
foreach($second_pid as $key=>$value){
$arr[$key]=$value['pid'];
$b = GoodsLogic::info($goods_id);
$second_pid = array();
$arr = $arr1 = array();
if ($b['base']['second_cate_id'] != 0) {
$second_pid = GoodsCategory::where("id in (" . $b['base']['second_cate_id'] . ")")->select();
if (!empty($second_pid)) {
foreach ($second_pid as $key => $value) {
$arr[$key] = $value['pid'];
}
$second_pid = array_unique($arr);
}
}
$third_pid = array();
if($b['base']['third_cate_id']!=0){
$third_pid = GoodsCategory::where("id in (".$b['base']['third_cate_id'].")")->select();
if(!empty($third_pid)){
foreach($third_pid as $key=>$value){
$arr1[$key]=$value['pid'];
if ($b['base']['third_cate_id'] != 0) {
$third_pid = GoodsCategory::where("id in (" . $b['base']['third_cate_id'] . ")")->select();
if (!empty($third_pid)) {
foreach ($third_pid as $key => $value) {
$arr1[$key] = $value['pid'];
}
$third_pid = array_unique($arr1);
}
}
$b['base']['first_cate_id'] = explode(",",$b['base']['first_cate_id']);
$b['base']['second_cate_id'] = explode(",",$b['base']['second_cate_id']);
$b['base']['third_cate_id']= explode(",",$b['base']['third_cate_id']);
$b['base']['first_cate_id'] = explode(",", $b['base']['first_cate_id']);
$b['base']['second_cate_id'] = explode(",", $b['base']['second_cate_id']);
$b['base']['third_cate_id'] = explode(",", $b['base']['third_cate_id']);
$subsidy = (new GoodsSubsidy())->getSubsidyById($b['base']['subsidy_id']);
return view('goods/goods/add', [
'category_lists_new' => $a,
'category_lists_new' => $a,
'category_first' => $b['base']['first_cate_id'],
'category_second' => $b['base']['second_cate_id'],
'second_pid' => $second_pid,
@ -292,14 +295,15 @@ class Goods extends ShopBase
'supplier_lists' => json_encode(Supplier::getNameColumn($this->shop_id), JSON_UNESCAPED_UNICODE),
'unit_lists' => json_encode(GoodsUnit::getNameColumn(), JSON_UNESCAPED_UNICODE),
'freight_lists' => json_encode(Freight::getNameColumn($this->shop_id), JSON_UNESCAPED_UNICODE),
'info' => json_encode(GoodsLogic::info($goods_id),JSON_UNESCAPED_UNICODE)
'info' => json_encode(GoodsLogic::info($goods_id), JSON_UNESCAPED_UNICODE),
'subsidy' => json_encode($subsidy, JSON_UNESCAPED_UNICODE),
]);
}
/**
* Notes: 删除
* @author 段誉(2021/4/15 10:49)
* @return \think\response\Json
* @author 段誉(2021/4/15 10:49)
*/
public function del()
{
@ -307,7 +311,7 @@ class Goods extends ShopBase
$id = $this->request->post('id');
(new GoodsValidate())->goCheck('del', ['goods_id' => $id, 'shop_id' => $this->shop_id]);
$result = GoodsLogic::del($this->shop_id, $id);
if($result) {
if ($result) {
return JsonServer::success('删除成功');
}
return JsonServer::error(GoodsLogic::getError());
@ -319,7 +323,8 @@ class Goods extends ShopBase
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function changeFields(){
public function changeFields()
{
$table = 'goods';
$pk_name = 'id';
$pk_value = $this->request->post('id');
@ -328,11 +333,11 @@ class Goods extends ShopBase
// 库存校验
$stock = GoodsModel::where('id', $pk_value)->value('stock');
if($field_value == 1 && $stock <= 0) {
if ($field_value == 1 && $stock <= 0) {
return JsonServer::error('库存为0的商品不允许上架');
}
$result = CommonLogic::changeTableValue($table,$pk_name,$pk_value,$field,$field_value);
if($result){
$result = CommonLogic::changeTableValue($table, $pk_name, $pk_value, $field, $field_value);
if ($result) {
event('UpdateCollect', ['goods_id' => $pk_value]);
return JsonServer::success('操作成功');
}
@ -342,13 +347,14 @@ class Goods extends ShopBase
/**
* 放回仓库
*/
public function backToWarehouse(){
public function backToWarehouse()
{
$id = $this->request->post('id', '', 'intval');
if(empty($id)) {
if (empty($id)) {
return JsonServer::error('id不存在');
}
$result = GoodsLogic::backToWarehouse($id);
if($result) {
if ($result) {
return JsonServer::success('操作成功');
}
return JsonServer::error('操作失败');
@ -378,21 +384,31 @@ class Goods extends ShopBase
if ($this->request->isAjax()) {
$params = (new GoodsStatusValidate())->goCheck(null, ['shop_id' => $this->shop_id]);
$result = GoodsLogic::setStatus($params['ids'], $params['status']);
if($result) {
if ($result) {
return JsonServer::success('操作成功');
}
return JsonServer::error(GoodsLogic::getError());
}
}
public function export()
{
$ids = $this->request->post('ids');
$result = GoodsLogic::exportData($this->shop_id, $ids);
if(false === $result) {
if (false === $result) {
return JsonServer::error(GoodsLogic::getError() ?: '导出失败');
}
return JsonServer::success('', ['url' => $result['url']]);
}
public function goodsSubsidy()
{
if ($this->request->isAjax()) {
$get = $this->request->get();
$lists = (new GoodsSubsidy())->getSubsidy($get);
return JsonServer::success('', $lists);
}
return view('');
}
}

@ -35,6 +35,7 @@ use app\common\server\ExportExcelServer;
use app\common\server\UrlServer;
use think\facade\Db;
use app\common\model\shop\Shop;
use app\common\model\goods\GoodsSubsidy;
/**
* 商品管理-逻辑
@ -452,7 +453,9 @@ class GoodsLogic extends Logic
'purchase_price' =>$purchase_price,
'issuing_price' =>$issuing_price,
'goods_remark' =>$post['goods_remark'],
'work_remark' =>$post['work_remark']
'work_remark' =>$post['work_remark'],
'doudian_data' =>'',
'subsidy_id' =>$post['subsidy_id'],
];
// 判断是否为未审核通过的商品
@ -991,7 +994,9 @@ class GoodsLogic extends Logic
'purchase_price' =>$purchase_price,
'issuing_price' =>$issuing_price,
'goods_remark' =>$post['goods_remark'],
'work_remark' =>$post['work_remark']
'work_remark' =>$post['work_remark'],
'doudian_data' =>'',
'subsidy_id' =>$post['subsidy_id'],
];
$goods = Goods::create($data);
foreach($post['c_name'] as $key=>$value){
@ -1319,6 +1324,5 @@ class GoodsLogic extends Logic
return false;
}
}
}

@ -65,6 +65,7 @@ class GoodsValidate extends Validate
'stock_warn' => 'integer|egt:0',
'code' => 'checkCode',
'sort' => 'egt:0',
'subsidy_id' => 'require',
];
protected $message = [
@ -92,6 +93,7 @@ class GoodsValidate extends Validate
'stock_warn.integer' => '库存预警须为整数',
'stock_warn.egt' => '库存预警须大于或等于0',
'sort.egt' => '排序值不能小于0',
'subsidy_id.require' => '请选择商品返补比例',
];
public function sceneAdd()

@ -190,6 +190,64 @@
$(this).find('.goods-spec-img-del-x').show();
// $(this).find('.goods-spec-img-del-x').hide();
});
var subsidy = {$subsidy | raw};
if (subsidy) {
const h = `
<table class="layui-table">
<thead>
<tr>
<th>商家利润比例</th>
<th>商品让利比例</th>
<th>商品全返比例</th>
</tr>
</thead>
<tbody>
<tr>
<td>${subsidy.profit}</td>
<td>${subsidy.discount}</td>
<td>${subsidy.subsidy}</td>
</tr>
</tbody>
</table>
`
$("#goods_subsidy_table").html(h);
$("#subsidy_id").val(subsidy.id)
}
// 商品选择让利
$(document).on("click", "#select-goods-subsidy", function () {
layer.open({
type: 2
,title: '选择比例'
,content: '{:url("goods.Goods/goodsSubsidy")}'
,area: ['90%', '90%']
,btn: ['确认', '取消']
,yes: function(index, layero){
var data = window["layui-layer-iframe" + index].callbackdata();
const html = `
<table class="layui-table">
<thead>
<tr>
<th>商家利润比例</th>
<th>商品让利比例</th>
<th>商品全返比例</th>
</tr>
</thead>
<tbody>
<tr>
<td>${data[0].profit}</td>
<td>${data[0].discount}</td>
<td>${data[0].subsidy}</td>
</tr>
</tbody>
</table>
`
$("#goods_subsidy_table").html(html);
$("#subsidy_id").val(data[0]['id'])
}
})
})
form.on('checkbox(first)', function (data) {
var second_category = "";
for (var i in categorys) {
@ -869,7 +927,7 @@ $('input[name="work_remark"]').val(goods_info['base']['work_remark']);
d++;
}
});
$("input[name=is_show_stock][value="+goods_info['base']['is_show_stock']+"]").prop("checked",true); //是否显示库存
$("input[name=express_type][value="+goods_info['base']['express_type']+"]").prop("checked",true);
$('input[name="express_money"]').val(goods_info['base']['express_money']);

@ -1,4 +1,19 @@
<div class="layui-tab-item">
<!--商品让利-->
<div class="layui-form-item">
<div style="height: 40px">
<label class="layui-form-label"><span class="form-label-asterisk">*</span>商品返补比例:</label>
<div class="layui-input-inline">
<div class="layui-input-inline" style="display: flex">
<input type="hidden" id="subsidy_id" name="subsidy_id">
<a id="select-goods-subsidy" class="layui-btn layui-btn-normal ">选择</a>
</div>
</div>
</div>
<div id="goods_subsidy_table" style="padding: 0 46px;"></div>
</div>
<!--库存预警-->
<div class="layui-form-item">
<label class="layui-form-label">库存预警:</label>

@ -0,0 +1,75 @@
{layout name="layout1" /}
<div class="layui-fluid">
<div class="layui-card">
<div class="layui-tab layui-tab-card" lay-filter="tab-all">
<div class="layui-tab-item layui-show">
<div class="layui-card">
<div class="layui-card-body">
<table id="goods-lists" lay-filter="goods-lists"></table>
<script type="text/html" id="goods-info">
<img src="{{d.image}}" style="height:60px;width: 60px" class="image-show"> {{d.name}}
</script>
</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item layui-hide">
<input type="button" lay-submit lay-filter="select-submit" class="select-submit" id="select-submit"
value="确认">
</div>
</div>
<style>
.layui-table-cell {
height: auto;
}
</style>
<script>
var table;
layui.config({
version: "{$front_version}",
base: '/static/lib/' //静态资源所在路径
}).use(['table', 'form'], function () {
var $ = layui.$
, form = layui.form
, element = layui.element;
});
layui.define(['table', 'form'], function (exports) {
var $ = layui.$
, form = layui.form;
table = layui.table;
table.render({
id: 'goods-lists'
, elem: '#goods-lists'
, url: '{:url("goods.Goods/goodsSubsidy")}' //模拟接口
, cols: [[
{type: 'radio'}
, {field: 'profit', title: '商家利润比例', align: "center"}
, {field: 'discount', title: '商品让利比例', align: "center"}
, {field: 'subsidy', title: '商品全返比例', align: "center"}
]]
, page: true
, text: {none: '暂无数据!'}
, parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
return {
"code": res.code,
"msg": res.msg,
"count": res.data.count, //解析数据长度
"data": res.data.lists, //解析数据列表
};
},
response: {
statusCode: 1
}
});
})
var callbackdata = function () {
var data = table.checkStatus('goods-lists').data
, index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
return data;
}
</script>