From 87590024d52c9202115cf1f1eac40be796bc0005 Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Mon, 17 Dec 2018 01:22:10 +0800 Subject: [PATCH] goods category --- application/admin/config/app.php | 18 +-- application/admin/controller/Admin.php | 1 + application/admin/controller/Goods.php | 3 + .../admin/controller/GoodsCategory.php | 112 ++------------ application/admin/controller/User.php | 1 + application/admin/lang/zh-cn.php | 15 ++ .../admin/view/default/goods/save_info.html | 4 +- .../view/default/goodscategory/index.html | 42 +++--- .../admin/view/default/public/footer.html | 2 +- application/service/GoodsService.php | 138 ++++++++++++++---- application/service/ResourcesService.php | 24 +++ application/service/SearchService.php | 4 +- extend/base/Uploader.php | 7 +- .../ueditor/themes/default/css/ueditor.css | 24 +-- .../common/lib/ueditor/ueditor.config.js | 2 +- 15 files changed, 226 insertions(+), 171 deletions(-) diff --git a/application/admin/config/app.php b/application/admin/config/app.php index 1890fd05e..a0b8b8c1e 100644 --- a/application/admin/config/app.php +++ b/application/admin/config/app.php @@ -50,7 +50,7 @@ return array( 'imageUrlPrefix' => '', // 上传保存路径,可以自定义保存路径和文件名格式 - 'imagePathFormat' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/image/{yyyy}/{mm}/{dd}/{time}{rand:6}', + 'imagePathFormat' => __MY_ROOT__.'static/upload/image/'.input('path_type', 'other').'/{yyyy}/{mm}/{dd}/{time}{rand:6}', // 涂鸦图片上传配置项 @@ -61,7 +61,7 @@ return array( 'scrawlFieldName' => 'upfile', // 上传保存路径,可以自定义保存路径和文件名格式 - 'scrawlPathFormat' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/scrawl/{yyyy}/{mm}/{dd}/{time}{rand:6}', + 'scrawlPathFormat' => __MY_ROOT__.'static/upload/image/'.input('path_type', 'other').'/{yyyy}/{mm}/{dd}/{time}{rand:6}', // 上传大小限制,单位B 'scrawlMaxSize' => MyC('home_max_limit_image', 2048000, true), @@ -78,7 +78,7 @@ return array( 'snapscreenActionName' => 'uploadimage', // 上传保存路径,可以自定义保存路径和文件名格式 - 'snapscreenPathFormat' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/screenshot/{yyyy}/{mm}/{dd}/{time}{rand:6}', + 'snapscreenPathFormat' => __MY_ROOT__.'static/upload/image/'.input('path_type', 'other').'/{yyyy}/{mm}/{dd}/{time}{rand:6}', // 图片访问路径前缀 'snapscreenUrlPrefix' => '', @@ -98,7 +98,7 @@ return array( 'catcherFieldName' => 'source', // 上传保存路径,可以自定义保存路径和文件名格式 - 'catcherPathFormat' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/catchimage/{yyyy}/{mm}/{dd}/{time}{rand:6}', + 'catcherPathFormat' => __MY_ROOT__.'static/upload/image/'.input('path_type', 'other').'/{yyyy}/{mm}/{dd}/{time}{rand:6}', // 图片访问路径前缀 'catcherUrlPrefix' => '', @@ -118,7 +118,7 @@ return array( 'videoFieldName' => 'upfile', // 上传保存路径,可以自定义保存路径和文件名格式 - 'videoPathFormat' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/video/{yyyy}/{mm}/{dd}/{time}{rand:6}', + 'videoPathFormat' => __MY_ROOT__.'static/upload/video/'.input('path_type', 'other').'/{yyyy}/{mm}/{dd}/{time}{rand:6}', // 视频访问路径前缀 'videoUrlPrefix' => '', @@ -138,7 +138,7 @@ return array( 'fileFieldName' => 'upfile', // 上传保存路径,可以自定义保存路径和文件名格式 - 'filePathFormat' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/file/{yyyy}/{mm}/{dd}/{time}{rand:6}', + 'filePathFormat' => __MY_ROOT__.'static/upload/file/'.input('path_type', 'other').'/{yyyy}/{mm}/{dd}/{time}{rand:6}', // 文件访问路径前缀 'fileUrlPrefix' => '', @@ -155,7 +155,7 @@ return array( 'imageManagerActionName'=> 'listimage', // 指定要列出图片的目录 - 'imageManagerListPath' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/image/', + 'imageManagerListPath' => __MY_ROOT__.'static/upload/image/'.input('path_type', 'other').'/', // 每次列出文件数量 'imageManagerListSize' => 20, @@ -175,7 +175,7 @@ return array( 'fileManagerActionName' => 'listfile', // 指定要列出文件的目录 - 'fileManagerListPath' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/file/', + 'fileManagerListPath' => __MY_ROOT__.'static/upload/file/'.input('path_type', 'other').'/', // 文件访问路径前缀 'fileManagerUrlPrefix' => '', @@ -190,7 +190,7 @@ return array( 'videoManagerActionName' => 'listvideo', // 指定要列出文件的目录 - 'videoManagerListPath' => __MY_ROOT__.'static/upload/'.input('path_type', 'other').'/video/', + 'videoManagerListPath' => __MY_ROOT__.'static/upload/video/'.input('path_type', 'other').'/', // 文件访问路径前缀 'videoManagerUrlPrefix' => '', diff --git a/application/admin/controller/Admin.php b/application/admin/controller/Admin.php index 52020f5ac..b2b5075f8 100755 --- a/application/admin/controller/Admin.php +++ b/application/admin/controller/Admin.php @@ -55,6 +55,7 @@ class Admin extends Common 'number' => $number, 'total' => $total, 'where' => $params, + 'page' => isset($params['page']) ? intval($params['page']) : 1, 'url' => url('admin/admin/index'), ); $page = new \base\Page($page_params); diff --git a/application/admin/controller/Goods.php b/application/admin/controller/Goods.php index 9e4b937e2..624ae5a1d 100755 --- a/application/admin/controller/Goods.php +++ b/application/admin/controller/Goods.php @@ -131,6 +131,9 @@ class Goods extends Common // 参数 $this->assign('params', $params); + // 编辑器文件存放地址 + $this->assign('editor_path_type', 'goods'); + return $this->fetch(); } diff --git a/application/admin/controller/GoodsCategory.php b/application/admin/controller/GoodsCategory.php index b5a05d4b7..5b7d796e8 100755 --- a/application/admin/controller/GoodsCategory.php +++ b/application/admin/controller/GoodsCategory.php @@ -1,7 +1,8 @@ assign('common_is_text_list', lang('common_is_text_list')); - $this->display('Index'); + + // 编辑器文件存放地址 + $this->assign('editor_path_type', 'goods_category'); + + return $this->fetch(); } /** @@ -62,43 +67,11 @@ class GoodsCategory extends Common $this->error(lang('common_unauthorized_access')); } - // 获取数据 - $field = array('id', 'pid', 'icon', 'name', 'sort', 'is_enable', 'bg_color', 'big_images', 'vice_name', 'describe', 'is_home_recommended'); - $data = db('GoodsCategory')->field($field)->where(array('pid'=>intval(I('id', 0))))->select(); - if(!empty($data)) - { - $image_host = config('IMAGE_HOST'); - foreach($data as &$v) - { - $v['is_son'] = $this->IsExistSon($v['id']); - $v['ajax_url'] = url('Admin/GoodsCategory/GetNodeSon', array('id'=>$v['id'])); - $v['delete_url'] = url('Admin/GoodsCategory/Delete'); - $v['icon_url'] = empty($v['icon']) ? '' : $image_host.$v['icon']; - $v['big_images_url'] = empty($v['big_images']) ? '' : $image_host.$v['big_images']; - $v['json'] = json_encode($v); - } - } - $msg = empty($data) ? lang('common_not_data_tips') : lang('common_operation_success'); - $this->ajaxReturn($msg, 0, $data); + // 开始操作 + $ret = GoodsService::GoodsCategoryNodeSon(input()); + return json($ret); } - /** - * [IsExistSon 节点是否存在子数据] - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-25T15:22:47+0800 - * @param [int] $id [节点id] - * @return [string] [有数据ok, 则no] - */ - private function IsExistSon($id) - { - if(!empty($id)) - { - return (db('GoodsCategory')->where(array('pid'=>$id))->count() > 0) ? 'ok' : 'no'; - } - return 'no'; - } /** * [Save 分类保存] @@ -115,62 +88,9 @@ class GoodsCategory extends Common $this->error(lang('common_unauthorized_access')); } - // icon - $this->FileSave('icon', 'file_icon', 'goods_category'); - - // 大图片 - $this->FileSave('big_images', 'file_big_images', 'goods_category'); - - // id为空则表示是新增 - $m = D('GoodsCategory'); - - // 公共额外数据处理 - $m->sort = intval(I('sort')); - - // 添加 - if(empty($_POST['id'])) - { - if($m->create($_POST, 1)) - { - // 额外数据处理 - $m->add_time = time(); - $m->name = I('name'); - $m->vice_name = I('vice_name'); - $m->describe = I('describe'); - $m->is_home_recommended = intval(I('is_home_recommended', 0)); - - // 写入数据库 - if($m->add()) - { - $this->ajaxReturn(lang('common_operation_add_success')); - } else { - $this->ajaxReturn(lang('common_operation_add_error'), -100); - } - } - } else { - // 编辑 - if($m->create($_POST, 2)) - { - // 额外数据处理 - $m->name = I('name'); - $m->upd_time = time(); - $m->vice_name = I('vice_name'); - $m->describe = I('describe'); - $m->is_home_recommended = intval(I('is_home_recommended', 0)); - - // 移除 id - unset($m->id, $m->pid); - - // 更新数据库 - if($m->where(array('id'=>I('id')))->save()) - { - $this->ajaxReturn(lang('common_operation_edit_success')); - } else { - $this->ajaxReturn(lang('common_operation_edit_error'), -100); - } - } - } - $this->ajaxReturn($m->getError(), -1); + // 开始操作 + $ret = GoodsService::GoodsCategorySave(input()); + return json($ret); } /** @@ -192,12 +112,12 @@ class GoodsCategory extends Common { if($m->delete(I('id'))) { - $this->ajaxReturn(lang('common_operation_delete_success')); + return json(lang('common_operation_delete_success')); } else { - $this->ajaxReturn(lang('common_operation_delete_error'), -100); + return json(lang('common_operation_delete_error'), -100); } } else { - $this->ajaxReturn($m->getError(), -1); + return json($m->getError(), -1); } } } diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 9eafa7f1b..dc2be4d92 100755 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -56,6 +56,7 @@ class User extends Common 'number' => $number, 'total' => $total, 'where' => $params, + 'page' => isset($params['page']) ? intval($params['page']) : 1, 'url' => url('admin/user/index'), ); $page = new \base\Page($page_params); diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index 22964fe0a..75705c0ba 100644 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -300,5 +300,20 @@ return array( 'goods_video_text' => '短视频', 'goods_video_tips' => '视频比图文更有具带入感,仅支持 mp4 格式', + + + // 商品分类 + 'goods_category_add_name' => '分类添加', + 'goods_category_edit_name' => '分类编辑', + + 'goods_category_big_images_text' => '大图片', + + 'goods_category_vice_name_text' => '副名称', + 'goods_category_vice_name_format' => '副名称最大60个字符', + + 'goods_category_describe_text' => '描述', + 'goods_category_describe_format' => '描述最大200个字符', + + 'goods_category_home_recommended_text' => '首页推荐', ); ?> \ No newline at end of file diff --git a/application/admin/view/default/goods/save_info.html b/application/admin/view/default/goods/save_info.html index 6b85b54da..dd66294a4 100755 --- a/application/admin/view/default/goods/save_info.html +++ b/application/admin/view/default/goods/save_info.html @@ -137,7 +137,7 @@ {{/if}}
+上传图片
- +
@@ -321,7 +321,7 @@
- +
diff --git a/application/admin/view/default/goodscategory/index.html b/application/admin/view/default/goodscategory/index.html index a645a4843..74c463129 100755 --- a/application/admin/view/default/goodscategory/index.html +++ b/application/admin/view/default/goodscategory/index.html @@ -18,32 +18,32 @@
-
+
- - - - -
+
    +
  • + + +
  • +
+
+上传图片
- - - - -
+
    +
  • + + +
  • +
+
+上传图片
@@ -61,8 +61,8 @@
- - {{/foreach}} @@ -86,9 +86,9 @@ -
+
- +

{{:lang('common_form_loading_tips')}}

@@ -101,5 +101,5 @@ {{include file="public/footer" /}} \ No newline at end of file diff --git a/application/admin/view/default/public/footer.html b/application/admin/view/default/public/footer.html index 2638c6952..01176f520 100755 --- a/application/admin/view/default/public/footer.html +++ b/application/admin/view/default/public/footer.html @@ -1,7 +1,7 @@ {{include file="public/common" /}} - + diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index bb64144ee..5e39cabe4 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -965,7 +965,7 @@ class GoodsService // 其它附件 $data_fields = ['home_recommended_images', 'video']; - $attachment = self::GetGoodsAttachmentParams($params, $data_fields); + $attachment = ResourcesService::AttachmentParams($params, $data_fields); if($attachment['code'] != 0) { return $attachment; @@ -1238,30 +1238,6 @@ class GoodsService return DataReturn('success', 0, $result); } - /** - * 附件集合处理 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-08-07 - * @desc description - * @param [array] $params [输入参数] - * @param [array] $data [字段列表] - */ - private static function GetGoodsAttachmentParams($params, $data) - { - $result = []; - if(!empty($data)) - { - foreach($data as $field) - { - $result[$field] = isset($params[$field]) ? ResourcesService::AttachmentPathHandle($params[$field]) : ''; - } - } - - return DataReturn('success', 0, $result); - } - /** * 商品分类添加 * @author Devil @@ -1833,5 +1809,117 @@ class GoodsService } return DataReturn('没有相关规格类型', -100); } + + /** + * 获取商品分类节点数据 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2018-12-16T23:54:46+0800 + * @param [array] $params [输入参数] + */ + public static function GoodsCategoryNodeSon($params = []) + { + // id + $id = isset($params['id']) ? intval($params['id']) : 0; + + // 获取数据 + $field = 'id,pid,icon,name,sort,is_enable,bg_color,big_images,vice_name,describe,is_home_recommended'; + $data = db('GoodsCategory')->field($field)->where(['pid'=>$id])->select(); + if(!empty($data)) + { + $image_host = config('IMAGE_HOST'); + foreach($data as &$v) + { + $v['is_son'] = (db('GoodsCategory')->where(['pid'=>$v['id']])->count() > 0) ? 'ok' : 'no'; + $v['ajax_url'] = url('admin/goodscategory/getnodeson', array('id'=>$v['id'])); + $v['delete_url'] = url('admin/goodscategory/delete'); + $v['icon_url'] = empty($v['icon']) ? '' : $image_host.$v['icon']; + $v['big_images_url'] = empty($v['big_images']) ? '' : $image_host.$v['big_images']; + $v['json'] = json_encode($v); + } + return DataReturn('操作成功', 0, $data); + } + return DataReturn('没有相关数据', -100); + } + + /** + * 商品分类保存 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2018-12-17T01:04:03+0800 + * @param [array] $params [输入参数] + */ + public static function GoodsCategorySave($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'length', + 'key_name' => 'name', + 'checked_data' => '2,16', + 'error_msg' => '名称格式 2~16 个字符', + ], + [ + 'checked_type' => 'length', + 'key_name' => 'vice_name', + 'checked_data' => '60', + 'is_checked' => 1, + 'error_msg' => '副名称格式 最多30个字符', + ], + [ + 'checked_type' => 'length', + 'key_name' => 'describe', + 'checked_data' => '200', + 'is_checked' => 1, + 'error_msg' => '描述格式 最多200个字符', + ], + ]; + $ret = params_checked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 其它附件 + $data_fields = ['icon', 'big_images']; + $attachment = ResourcesService::AttachmentParams($params, $data_fields); + if($attachment['code'] != 0) + { + return $attachment; + } + + // 数据 + $data = [ + 'name' => $params['name'], + 'pid' => isset($params['pid']) ? intval($params['pid']) : 0, + 'vice_name' => isset($params['vice_name']) ? $params['vice_name'] : '', + 'describe' => isset($params['describe']) ? $params['describe'] : '', + 'bg_color' => isset($params['bg_color']) ? $params['bg_color'] : '', + 'is_home_recommended' => isset($params['is_home_recommended']) ? intval($params['is_home_recommended']) : 0, + 'sort' => isset($params['sort']) ? intval($params['sort']) : 0, + 'icon' => $attachment['data']['icon'], + 'big_images' => $attachment['data']['big_images'], + ]; + + // 添加 + if(empty($params['id'])) + { + $data['add_time'] = time(); + if(db('GoodsCategory')->insertGetId($data) > 0) + { + return DataReturn('添加成功', 0); + } + return DataReturn('添加失败', -100); + } else { + $data['upd_time'] = time(); + if(db('GoodsCategory')->where(['id'=>intval($params['id'])])->update($data)) + { + return DataReturn('编辑成功', 0); + } + return DataReturn('编辑失败', -100); + } + } } ?> \ No newline at end of file diff --git a/application/service/ResourcesService.php b/application/service/ResourcesService.php index a7e7e0c78..daa3f6484 100755 --- a/application/service/ResourcesService.php +++ b/application/service/ResourcesService.php @@ -190,6 +190,30 @@ class ResourcesService return str_replace([__MY_URL__, __MY_ROOT__], DS, $value); } + /** + * 附件集合处理 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-07 + * @desc description + * @param [array] $params [输入参数] + * @param [array] $data [字段列表] + */ + public static function AttachmentParams($params, $data) + { + $result = []; + if(!empty($data)) + { + foreach($data as $field) + { + $result[$field] = isset($params[$field]) ? self::AttachmentPathHandle($params[$field]) : ''; + } + } + + return DataReturn('success', 0, $result); + } + /** * APP获取首页导航 * @author Devil diff --git a/application/service/SearchService.php b/application/service/SearchService.php index b0825276c..29a724129 100755 --- a/application/service/SearchService.php +++ b/application/service/SearchService.php @@ -95,11 +95,11 @@ class SearchService } if(!empty($params['min_price'])) { - $where[] = ['g.price', 'EGT', $params['min_price']]; + $where[] = ['g.min_price', 'EGT', $params['min_price']]; } if(!empty($params['max_price'])) { - $where[] = ['g.price', 'LT', $params['max_price']]; + $where[] = ['g.min_price', 'LT', $params['max_price']]; } // 获取商品总数 diff --git a/extend/base/Uploader.php b/extend/base/Uploader.php index 918eee7bb..2f242b544 100755 --- a/extend/base/Uploader.php +++ b/extend/base/Uploader.php @@ -108,13 +108,14 @@ class Uploader return; } +if (!is_writeable($dirname)) { + $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE"); + return; + } //创建目录失败 if (!is_dir($dirname) && !mkdir($dirname, 0777, true)) { $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR"); return; - } else if (!is_writeable($dirname)) { - $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE"); - return; } //移动文件 diff --git a/public/static/common/lib/ueditor/themes/default/css/ueditor.css b/public/static/common/lib/ueditor/themes/default/css/ueditor.css index 43afae73f..0b4c14898 100755 --- a/public/static/common/lib/ueditor/themes/default/css/ueditor.css +++ b/public/static/common/lib/ueditor/themes/default/css/ueditor.css @@ -1166,11 +1166,13 @@ div.edui-box { word-wrap: break-word; word-break: normal; } +#edui_fixedlayer { + z-index: 1200 !important; +} /* 弹出对话框按钮和对话框大小 */ .edui-default .edui-dialog { - z-index: 2000; position: absolute; - + z-index: 1210 !important; } .edui-dialog div{ @@ -1226,30 +1228,30 @@ div.edui-box { } .edui-default .edui-dialog-titlebar { - height: 26px; + height: 30px; border-bottom: 1px solid #c6c6c6; /*background: url(../images/dialog-title-bg.png) repeat-x bottom;*/ position: relative; cursor: move; background-color: #f5f5f5; - border-top-right-radius: 8px; - border-top-left-radius: 8px; + border-top-right-radius: 3px; + border-top-left-radius: 3px; } .edui-default .edui-dialog-caption { font-weight: bold; font-size: 12px; - line-height: 26px; + line-height: 30px; padding-left: 5px; } .edui-default .edui-dialog-draghandle { - height: 26px; + height: 30px; } .edui-default .edui-dialog-closebutton { position: absolute !important; right: 5px; - top: 3px; + top: 5px; } .edui-default .edui-dialog-closebutton .edui-button-body { @@ -1265,8 +1267,8 @@ div.edui-box { .edui-default .edui-dialog-foot { height: 40px; - border-bottom-right-radius: 8px; - border-bottom-left-radius: 8px; + border-bottom-right-radius: 3px; + border-bottom-left-radius: 3px; } .edui-default .edui-dialog-buttons { @@ -1304,7 +1306,7 @@ div.edui-box { filter: alpha(opacity = 30); background-color: #ccc; position: absolute; - /*z-index: 1999;*/ + z-index: 1200 !important; } .edui-default .edui-dialog-dragmask { diff --git a/public/static/common/lib/ueditor/ueditor.config.js b/public/static/common/lib/ueditor/ueditor.config.js index b07196a08..1d0eac69f 100755 --- a/public/static/common/lib/ueditor/ueditor.config.js +++ b/public/static/common/lib/ueditor/ueditor.config.js @@ -24,7 +24,7 @@ /** * 服务器地址 */ - var SERVER_URL = $('#editor-tag').data('url'); + var SERVER_URL = $('#upload-editor-view').data('url'); /** * 配置项主体。注意,此处所有涉及到路径的配置别遗漏URL变量。 */