diff --git a/app/common/model/goods/GoodsSubsidy.php b/app/common/model/goods/GoodsSubsidy.php index 390bb0c5..8e45e898 100644 --- a/app/common/model/goods/GoodsSubsidy.php +++ b/app/common/model/goods/GoodsSubsidy.php @@ -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) . '%'; + } } \ No newline at end of file diff --git a/app/shop/controller/goods/Goods.php b/app/shop/controller/goods/Goods.php index be8ae3f9..88800c4e 100755 --- a/app/shop/controller/goods/Goods.php +++ b/app/shop/controller/goods/Goods.php @@ -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(''); + } } diff --git a/app/shop/logic/goods/GoodsLogic.php b/app/shop/logic/goods/GoodsLogic.php index 89383007..eeaaaa1d 100755 --- a/app/shop/logic/goods/GoodsLogic.php +++ b/app/shop/logic/goods/GoodsLogic.php @@ -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; } } - } diff --git a/app/shop/validate/goods/GoodsValidate.php b/app/shop/validate/goods/GoodsValidate.php index 400d2c44..a29549f0 100755 --- a/app/shop/validate/goods/GoodsValidate.php +++ b/app/shop/validate/goods/GoodsValidate.php @@ -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() diff --git a/app/shop/view/goods/goods/add.html b/app/shop/view/goods/goods/add.html index 09d67d60..978531b7 100755 --- a/app/shop/view/goods/goods/add.html +++ b/app/shop/view/goods/goods/add.html @@ -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 = ` + + + + + + + + + + + + + + + +
商家利润比例商品让利比例商品全返比例
${subsidy.profit}${subsidy.discount}${subsidy.subsidy}
+ ` + $("#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 = ` + + + + + + + + + + + + + + + +
商家利润比例商品让利比例商品全返比例
${data[0].profit}${data[0].discount}${data[0].subsidy}
+ ` + $("#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']); diff --git a/app/shop/view/goods/goods/goods_sale_setting.html b/app/shop/view/goods/goods/goods_sale_setting.html index 3d009eb8..a2ab0275 100755 --- a/app/shop/view/goods/goods/goods_sale_setting.html +++ b/app/shop/view/goods/goods/goods_sale_setting.html @@ -1,4 +1,19 @@
+ +
+
+ +
+
+ + 选择 +
+
+
+ +
+
+
diff --git a/app/shop/view/goods/goods/goods_subsidy.html b/app/shop/view/goods/goods/goods_subsidy.html new file mode 100755 index 00000000..b657a96e --- /dev/null +++ b/app/shop/view/goods/goods/goods_subsidy.html @@ -0,0 +1,75 @@ +{layout name="layout1" /} +
+
+
+
+
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + \ No newline at end of file