diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index a7b3f4673..4967c888c 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -17,24 +17,24 @@ use app\service\ResourcesService; use app\service\GoodsService; use app\service\RegionService; use app\service\BrandService; -use app\service\GoodsParamsService; -use app\service\GoodsSpecService; /** * 商品管理 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-01T21:51:08+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ class Goods extends Base { /** * 列表 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-06T21:31:53+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ public function Index() { @@ -43,10 +43,11 @@ class Goods extends Base /** * 详情 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2019-08-05T08:21:54+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ public function Detail() { @@ -69,10 +70,11 @@ class Goods extends Base /** * 添加/编辑页面 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-14T21:37:02+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ public function SaveInfo() { @@ -113,28 +115,15 @@ class Goods extends Base // 获取商品编辑参数 $assign['parameters'] = GoodsService::GoodsEditParameters($data['id']); - // 商品规格模板 - $spec_template = GoodsSpecService::GoodsCategorySpecTemplateList(['category_ids'=>$data['category_ids']]); - $assign['goods_spec_template_list'] = $spec_template['data']; + // 基础模板 + $goods_base_template = GoodsService::GoodsBaseTemplate(['category_ids'=>$data['category_ids']]); + $assign['goods_base_template'] = $goods_base_template['data']; } // 规格扩展数据 $goods_spec_extends = GoodsService::GoodsSpecificationsExtends($params); $assign['goods_specifications_extends'] = $goods_spec_extends['data']; - // 商品参数模板 - $data_params = [ - 'm' => 0, - 'n' => 0, - 'where' => [ - ['is_enable', '=', 1], - ['config_count', '>', 0], - ], - 'field' => 'id,name', - ]; - $params_template = GoodsParamsService::GoodsParamsTemplateList($data_params); - $assign['goods_params_template_list'] = $params_template['data']; - // 是否拷贝 $assign['is_copy'] = (isset($params['is_copy']) && $params['is_copy'] == 1) ? 1 : 0; @@ -161,10 +150,11 @@ class Goods extends Base /** * 添加/编辑 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-14T21:37:02+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ public function Save() { @@ -182,10 +172,11 @@ class Goods extends Base /** * 删除 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-15T11:03:30+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ public function Delete() { @@ -203,10 +194,11 @@ class Goods extends Base /** * 状态更新 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2017-01-12T22:23:06+0800 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description */ public function StatusUpdate() { @@ -223,13 +215,14 @@ class Goods extends Base } /** - * 规格模板 - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2017-01-12T22:23:06+0800 - */ - public function SpecTemplate() + * 基础模板 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-03-31 + * @desc description + */ + public function BaseTemplate() { // 是否ajax if(!IS_AJAX) @@ -240,7 +233,7 @@ class Goods extends Base // 开始操作 $params = $this->data_post; $params['admin'] = $this->admin; - return ApiService::ApiDataReturn(GoodsSpecService::GoodsCategorySpecTemplateList($params)); + return ApiService::ApiDataReturn(GoodsService::GoodsBaseTemplate($params)); } } ?> \ No newline at end of file diff --git a/app/admin/controller/Goodsparamstemplate.php b/app/admin/controller/Goodsparamstemplate.php index 7626aa7e0..3922c5e81 100755 --- a/app/admin/controller/Goodsparamstemplate.php +++ b/app/admin/controller/Goodsparamstemplate.php @@ -12,6 +12,7 @@ namespace app\admin\controller; use app\admin\controller\Base; use app\service\ApiService; +use app\service\GoodsService; use app\service\GoodsParamsService; /** @@ -85,6 +86,9 @@ class GoodsParamsTemplate extends Base // 参数配置 'parameters' => empty($data['config_data']) ? [] : $data['config_data'], + + // 商品分类 + 'goods_category_list' => GoodsService::GoodsCategoryList(['where'=>[['pid', '=', 0]]]), ]; // 编辑页面钩子 diff --git a/app/admin/form/Goodsparamstemplate.php b/app/admin/form/Goodsparamstemplate.php index 56195c9ae..2e4a06ed3 100644 --- a/app/admin/form/Goodsparamstemplate.php +++ b/app/admin/form/Goodsparamstemplate.php @@ -10,6 +10,8 @@ // +---------------------------------------------------------------------- namespace app\admin\form; +use app\service\GoodsService; + /** * 商品参数动态表格 * @author Devil @@ -23,6 +25,24 @@ class GoodsParamsTemplate // 基础条件 public $condition_base = []; + // 商品分类 + public $goods_category_list; + + /** + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-06-29 + * @desc description + * @param [array] $params [输入参数] + */ + public function __construct($params = []) + { + // 商品分类 + $res = GoodsService::GoodsCategoryList(['where'=>[['pid', '=', 0]]]); + $this->goods_category_list = empty($res) ? [] : array_column($res, 'name', 'id'); + } + /** * 入口 * @author Devil @@ -55,6 +75,18 @@ class GoodsParamsTemplate 'align' => 'center', 'width' => 80, ], + [ + 'label' => '商品分类', + 'view_type' => 'field', + 'view_key' => 'category_id', + 'view_data' => $this->goods_category_list, + 'search_config' => [ + 'form_type' => 'select', + 'where_type' => 'in', + 'data' => $this->goods_category_list, + 'is_multiple' => 1, + ], + ], [ 'label' => '名称', 'view_type' => 'field', diff --git a/app/admin/form/Goodsspectemplate.php b/app/admin/form/Goodsspectemplate.php index 49e52aeee..ea324b4ca 100644 --- a/app/admin/form/Goodsspectemplate.php +++ b/app/admin/form/Goodsspectemplate.php @@ -81,7 +81,6 @@ class GoodsSpecTemplate 'view_data' => $this->goods_category_list, 'search_config' => [ 'form_type' => 'select', - 'form_name' => 'category_id', 'where_type' => 'in', 'data' => $this->goods_category_list, 'is_multiple' => 1, diff --git a/app/admin/view/default/goods/save_info.html b/app/admin/view/default/goods/save_info.html index 98377c21d..da8982a1f 100755 --- a/app/admin/view/default/goods/save_info.html +++ b/app/admin/view/default/goods/save_info.html @@ -77,7 +77,7 @@

- {{if !empty($goods_category_list)}} {{foreach $goods_category_list as $v}} @@ -211,11 +211,11 @@
- + + {{if !empty($goods_base_template) and !empty($goods_base_template['params']) and is_array($goods_base_template['params'])}} + {{foreach $goods_base_template.params as $v}} + {{/foreach}} {{/if}} diff --git a/app/admin/view/default/goods/spec.html b/app/admin/view/default/goods/spec.html index c3986141c..fa887cc27 100644 --- a/app/admin/view/default/goods/spec.html +++ b/app/admin/view/default/goods/spec.html @@ -8,12 +8,15 @@

3. 商品添加成功后,仓库管理->仓库商品中添加并配置库存

-
- - {{if !empty($goods_spec_template_list)}} - {{foreach $goods_spec_template_list as $v}} - + {{if !empty($goods_base_template) and !empty($goods_base_template['spec']) and is_array($goods_base_template['spec'])}} + {{foreach $goods_base_template.spec as $v}} + {{/foreach}} {{/if}} diff --git a/app/admin/view/default/goodsparamstemplate/save_info.html b/app/admin/view/default/goodsparamstemplate/save_info.html index 603a1646f..4ad2d57a7 100755 --- a/app/admin/view/default/goodsparamstemplate/save_info.html +++ b/app/admin/view/default/goodsparamstemplate/save_info.html @@ -5,11 +5,22 @@
+
+ +
+ +
-
{{include file="public/goodsparamstemplate/tips" /}} @@ -37,7 +48,6 @@ 可直接点中参数行拖拽排序或点击上下移动 {{include file="public/goodsparamstemplate/table" /}}
-
diff --git a/app/admin/view/default/goodsspectemplate/save_info.html b/app/admin/view/default/goodsspectemplate/save_info.html index 9bb087916..78386a620 100755 --- a/app/admin/view/default/goodsspectemplate/save_info.html +++ b/app/admin/view/default/goodsspectemplate/save_info.html @@ -21,12 +21,10 @@
-
-
diff --git a/app/service/GoodsParamsService.php b/app/service/GoodsParamsService.php index e5b601ceb..47e924212 100755 --- a/app/service/GoodsParamsService.php +++ b/app/service/GoodsParamsService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\GoodsService; /** * 商品参数服务层 @@ -23,7 +24,7 @@ use think\facade\Db; class GoodsParamsService { /** - * 列表 + * 商品分类参数模板 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 @@ -31,17 +32,34 @@ class GoodsParamsService * @desc description * @param [array] $params [输入参数] */ - public static function GoodsParamsTemplateList($params = []) + public static function GoodsCategoryParamsTemplateList($params = []) { - $where = empty($params['where']) ? [] : $params['where']; - $field = empty($params['field']) ? '*' : $params['field']; - $order_by = empty($params['order_by']) ? 'id desc' : trim($params['order_by']); - $m = isset($params['m']) ? intval($params['m']) : 0; - $n = isset($params['n']) ? intval($params['n']) : 10; + // 请求类型 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'category_ids', + 'error_msg' => '请选择商品分类', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } - // 获取列表 - $data = Db::name('GoodsParamsTemplate')->where($where)->order($order_by)->field($field)->limit($m, $n)->select()->toArray(); - return DataReturn(MyLang('common.handle_success'), 0, self::GoodsParamsTemplateListHandle($data, $params)); + // 获取分类下所有分类id + $data = []; + $ids = GoodsService::GoodsCategoryParentIds($params['category_ids']); + if(!empty($ids)) + { + $where = [ + ['category_id', 'in', $ids], + ['is_enable', '=', 1], + ]; + $data = self::GoodsParamsTemplateListHandle(Db::name('GoodsParamsTemplate')->where($where)->field('id,name,config_count')->order('id desc')->select()->toArray(), $params); + } + return DataReturn(MyLang('common.operate_success'), 0, $data); } /** @@ -75,11 +93,11 @@ class GoodsParamsService $v['config_data'] = empty($config[$v['id']]) ? [] : $config[$v['id']]; // 时间 - if(isset($v['add_time'])) + if(array_key_exists('add_time', $v)) { $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']); } - if(isset($v['upd_time'])) + if(array_key_exists('upd_time', $v)) { $v['upd_time'] = empty($v['upd_time']) ? '' : date('Y-m-d H:i:s', $v['upd_time']); } @@ -101,6 +119,11 @@ class GoodsParamsService { // 请求类型 $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'category_id', + 'error_msg' => '请选择商品分类', + ], [ 'checked_type' => 'length', 'key_name' => 'name', @@ -123,6 +146,7 @@ class GoodsParamsService // 数据 $data = [ + 'category_id' => intval($params['category_id']), 'name' => $params['name'], 'config_count' => count($config['data']), 'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0, diff --git a/app/service/GoodsService.php b/app/service/GoodsService.php index 830627ff7..488ef9fff 100755 --- a/app/service/GoodsService.php +++ b/app/service/GoodsService.php @@ -17,6 +17,7 @@ use app\service\ResourcesService; use app\service\BrandService; use app\service\RegionService; use app\service\WarehouseGoodsService; +use app\service\GoodsSpecService; use app\service\GoodsParamsService; use app\service\GoodsCommentsService; @@ -3186,5 +3187,42 @@ class GoodsService ]; return $result; } + + /** + * 商品基础模板 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-08-26 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsBaseTemplate($params = []) + { + // 请求类型 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'category_ids', + 'error_msg' => '请选择商品分类', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 规格模板 + $spec = GoodsSpecService::GoodsCategorySpecTemplateList($params); + + // 参数模板 + $parameter = GoodsParamsService::GoodsCategoryParamsTemplateList($params); + + return DataReturn(MyLang('common.operate_success'), 0, [ + 'spec' => $spec['data'], + 'params' => $parameter['data'], + ]); + } } ?> \ No newline at end of file diff --git a/app/service/GoodsSpecService.php b/app/service/GoodsSpecService.php index acbcee7c0..b6d21c59f 100644 --- a/app/service/GoodsSpecService.php +++ b/app/service/GoodsSpecService.php @@ -57,7 +57,7 @@ class GoodsSpecService ['category_id', 'in', $ids], ['is_enable', '=', 1], ]; - $data = self::GoodsSpecTemplateListHandle(Db::name('GoodsSpecTemplate')->where($where)->field('id,name,content')->order('id desc')->select()->toArray()); + $data = self::GoodsSpecTemplateListHandle(Db::name('GoodsSpecTemplate')->where($where)->field('id,name,content')->order('id desc')->select()->toArray(), $params); } return DataReturn(MyLang('common.operate_success'), 0, $data); } diff --git a/public/static/admin/default/css/goods.css b/public/static/admin/default/css/goods.css index 2a07cc743..7a6e3bbe0 100755 --- a/public/static/admin/default/css/goods.css +++ b/public/static/admin/default/css/goods.css @@ -233,6 +233,9 @@ ul li { #specifications-quick-container .chosen-container { min-width: 120px; } +#specifications-quick-container select { + border: 0px; +} #specifications-quick-container .chosen-container-single .chosen-default, #specifications-quick-container .chosen-container-single .chosen-single { border-color: transparent !important; diff --git a/public/static/admin/default/js/goods.js b/public/static/admin/default/js/goods.js index 5c48be49a..5808cb846 100755 --- a/public/static/admin/default/js/goods.js +++ b/public/static/admin/default/js/goods.js @@ -708,7 +708,7 @@ $(function() }); // 商品参数模板选择 - $('.goods-template-params-select').on('change', function() + $('#parameters-quick-container select').on('change', function() { var value = $(this).val() || null; if(value != null) @@ -722,13 +722,14 @@ $(function() $('#parameters-quick-container textarea').val(value || ''); }); - // 商品规格模板数据获取、选择商品分类后异步读取 + // 商品规格模板和参数模板数据获取、选择商品分类后异步读取 var $spec_quick = $('#specifications-quick-container'); + var $params_quick = $('#parameters-quick-container'); $('select[name="category_id"]').on('change', function() { var value = $(this).val() || ''; $.ajax({ - url: RequestUrlHandle($spec_quick.data('url')), + url: RequestUrlHandle($(this).data('base-template-url')), type: 'POST', dataType: 'json', timeout: 305000, @@ -743,18 +744,41 @@ $(function() $(this).remove(); } }); - // 循环处理得到的最新模板 - if((result.data || null) != null && result.data.length > 0) + $params_quick.find('select option').each(function(k, v) { - var html = ''; - for(var i in result.data) + if(k > 0) { - html += ''; + $(this).remove(); + } + }); + // 循环处理得到的最新模板 + if((result.data || null) != null) + { + // 规格模板 + if((result.data.spec || null) != null && result.data.spec.length > 0) + { + var html = ''; + for(var i in result.data.spec) + { + html += ''; + } + $spec_quick.find('select').append(html); + } + + // 参数模板 + if((result.data.params || null) != null && result.data.params.length > 0) + { + var html = ''; + for(var i in result.data.params) + { + html += ''; + } + $params_quick.find('select').append(html); } - $spec_quick.find('select').append(html); } // 更新select组件 $spec_quick.find('select').trigger('chosen:updated'); + $params_quick.find('select').trigger('chosen:updated'); }, error: function(xhr, type) { @@ -765,40 +789,43 @@ $(function() // 规格模板选择 $(document).on('click', '#specifications-quick-container select option, #specifications-quick-container .chosen-container .chosen-results li.active-result', function() { - var value = $spec_quick.find('select').val() || null; - if(value == null) + if($(this).index() > 0) { - Prompt($spec_quick.data('spec-template-tips') || '规格模板数据有误'); - return false; - } - value = value.split(','); - var name = $spec_quick.find('select').find('option:selected').text(); - - // 名称是否已存在 - var status = true; - $('.spec-quick .goods-specifications table tbody tr').each(function() - { - var temp_name = $(this).find('td:first').find('input').val(); - if(temp_name == name) + var value = $spec_quick.find('select').val() || null; + if(value == null) { - status = false; + Prompt($spec_quick.data('spec-template-tips') || '规格模板数据有误'); + return false; } - }); - if(!status) - { - Prompt(($spec_quick.data('spec-template-name-tips') || '相同规格名称已经存在')+'('+name+')'); - return false; - } + value = value.split(','); + var name = $spec_quick.find('select').find('option:selected').data('origin-name'); - // 模拟点击添加一个规格类型 - $('.quick-spec-title-add').trigger('click'); - // 填入规格名称 - $('.spec-quick .goods-specifications table tbody tr:last td:first input').val(name); - // 加入规格值 - for(var i in value) - { - $('.spec-quick .goods-specifications table tbody tr:last td:last .quick-spec-value-add').trigger('click'); - $('.spec-quick .goods-specifications table tbody tr:last td:last .value-item:eq(-2) input').val(value[i]); + // 名称是否已存在 + var status = true; + $('.spec-quick .goods-specifications table tbody tr').each(function() + { + var temp_name = $(this).find('td:first').find('input').val(); + if(temp_name == name) + { + status = false; + } + }); + if(!status) + { + Prompt(($spec_quick.data('spec-template-name-tips') || '相同规格名称已经存在')+'('+name+')'); + return false; + } + + // 模拟点击添加一个规格类型 + $('.quick-spec-title-add').trigger('click'); + // 填入规格名称 + $('.spec-quick .goods-specifications table tbody tr:last td:first input').val(name); + // 加入规格值 + for(var i in value) + { + $('.spec-quick .goods-specifications table tbody tr:last td:last .quick-spec-value-add').trigger('click'); + $('.spec-quick .goods-specifications table tbody tr:last td:last .value-item:eq(-2) input').val(value[i]); + } } }); }); \ No newline at end of file