diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 931b56853..a7b3f4673 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -13,11 +13,12 @@ namespace app\admin\controller; use app\admin\controller\Base; use app\service\ApiService; use app\service\SystemBaseService; +use app\service\ResourcesService; use app\service\GoodsService; use app\service\RegionService; use app\service\BrandService; use app\service\GoodsParamsService; -use app\service\ResourcesService; +use app\service\GoodsSpecService; /** * 商品管理 @@ -111,6 +112,10 @@ 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']; } // 规格扩展数据 @@ -127,8 +132,8 @@ class Goods extends Base ], 'field' => 'id,name', ]; - $template = GoodsParamsService::GoodsParamsTemplateList($data_params); - $assign['goods_template_list'] = $template['data']; + $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; @@ -216,5 +221,26 @@ class Goods extends Base $params['admin'] = $this->admin; return ApiService::ApiDataReturn(GoodsService::GoodsStatusUpdate($params)); } + + /** + * 规格模板 + * @author Devil + * @blog http://gong.gg/ + * @version 0.0.1 + * @datetime 2017-01-12T22:23:06+0800 + */ + public function SpecTemplate() + { + // 是否ajax + if(!IS_AJAX) + { + return $this->error('非法访问'); + } + + // 开始操作 + $params = $this->data_post; + $params['admin'] = $this->admin; + return ApiService::ApiDataReturn(GoodsSpecService::GoodsCategorySpecTemplateList($params)); + } } ?> \ No newline at end of file diff --git a/app/admin/controller/Goodscart.php b/app/admin/controller/Goodscart.php new file mode 100644 index 000000000..bcdbc238a --- /dev/null +++ b/app/admin/controller/Goodscart.php @@ -0,0 +1,75 @@ +error('非法访问'); + } + + // 开始处理 + $params = $this->data_request; + $params['user_type'] = 'admin'; + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartDelete($params)); + } +} +?> \ No newline at end of file diff --git a/app/admin/controller/Goodsspectemplate.php b/app/admin/controller/Goodsspectemplate.php new file mode 100644 index 000000000..0adf1b8a6 --- /dev/null +++ b/app/admin/controller/Goodsspectemplate.php @@ -0,0 +1,161 @@ +data_request; + + // 数据 + $data = $this->data_detail; + + // 模板数据 + $assign = [ + // 商品分类 + 'goods_category_list' => GoodsService::GoodsCategoryList(['where'=>[['pid', '=', 0]]]), + ]; + + // 编辑页面钩子 + $hook_name = 'plugins_view_admin_goods_spec_template_save'; + MyViewAssign($hook_name.'_data', MyEventTrigger($hook_name, + [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'data_id' => isset($params['id']) ? $params['id'] : 0, + 'data' => &$data, + 'params' => &$params, + ])); + + // 数据/参数 + unset($params['id']); + $assign['data'] = $data; + $assign['params'] = $params; + + // 数据赋值 + MyViewAssign($assign); + return MyView(); + } + + /** + * 保存 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-11-27 + * @desc description + */ + public function Save() + { + // 是否ajax请求 + if(!IS_AJAX) + { + return $this->error('非法访问'); + } + + // 开始处理 + $params = $this->data_request; + return ApiService::ApiDataReturn(GoodsSpecService::GoodsSpecTemplateSave($params)); + } + + /** + * 删除 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-11-27 + * @desc description + */ + public function Delete() + { + // 是否ajax请求 + if(!IS_AJAX) + { + return $this->error('非法访问'); + } + + // 开始处理 + $params = $this->data_request; + $params['user_type'] = 'admin'; + return ApiService::ApiDataReturn(GoodsSpecService::GoodsSpecTemplateDelete($params)); + } + + /** + * 状态更新 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-11-27 + * @desc description + */ + public function StatusUpdate() + { + // 是否ajax请求 + if(!IS_AJAX) + { + return $this->error('非法访问'); + } + + // 开始处理 + $params = $this->data_request; + return ApiService::ApiDataReturn(GoodsSpecService::GoodsSpecTemplateStatusUpdate($params)); + } +} +?> \ No newline at end of file diff --git a/app/admin/form/Goodscart.php b/app/admin/form/Goodscart.php new file mode 100644 index 000000000..97fa93371 --- /dev/null +++ b/app/admin/form/Goodscart.php @@ -0,0 +1,165 @@ + [ + 'key_field' => 'id', + 'is_search' => 1, + 'is_delete' => 1, + 'delete_url' => MyUrl('admin/goodscart/delete'), + 'delete_key' => 'ids', + ], + // 表单配置 + 'form' => [ + [ + 'view_type' => 'checkbox', + 'is_checked' => 0, + 'checked_text' => '反选', + 'not_checked_text' => '全选', + 'align' => 'center', + 'width' => 80, + ], + [ + 'label' => '用户信息', + 'view_type' => 'module', + 'view_key' => 'lib/module/user', + 'grid_size' => 'sm', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'input', + 'form_name' => 'c.user_id', + 'where_type_custom' => 'in', + 'where_value_custom' => 'WhereValueUserInfo', + 'placeholder' => '请输入用户名/昵称/手机/邮箱', + ], + ], + [ + 'label' => '商品信息', + 'view_type' => 'module', + 'view_key' => 'goodscart/module/goods', + 'grid_size' => 'lg', + 'is_sort' => 1, + 'sort_field' => 'g.title', + 'search_config' => [ + 'form_type' => 'input', + 'form_name' => 'g.title|g.model|g.simple_desc|g.seo_title|g.seo_keywords|g.seo_keywords', + 'where_type' => 'like', + 'placeholder' => '请输入商品名称/简述/SEO信息' + ], + ], + [ + 'label' => '销售价格(元)', + 'view_type' => 'field', + 'view_key' => 'price', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'section', + 'form_name' => 'g.min_price', + 'is_point' => 1, + ], + ], + [ + 'label' => '原价(元)', + 'view_type' => 'field', + 'view_key' => 'original_price', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'section', + 'form_name' => 'g.min_original_price', + 'is_point' => 1, + ], + ], + [ + 'label' => '创建时间', + 'view_type' => 'field', + 'view_key' => 'add_time', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'datetime', + 'form_name' => 'c.add_time', + ], + ], + [ + 'label' => '操作', + 'view_type' => 'operate', + 'view_key' => 'goodscart/module/operate', + 'align' => 'center', + 'fixed' => 'right', + ], + ], + // 数据配置 + 'data' => [ + 'table_obj' => Db::name('Cart')->alias('c')->join('goods g', 'g.id=c.goods_id'), + 'select_field' => 'c.*, g.title, g.original_price, g.price, g.min_price, g.images', + 'order_by' => 'c.id desc', + 'detail_dkey' => 'c.id', + 'data_handle' => 'GoodsCartService::GoodsCartListHandle', + 'is_page' => 1, + 'data_params' => [ + 'is_public' => 0, + 'user_type' => 'admin', + ], + ], + ]; + } + + /** + * 用户信息条件处理 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-06-30 + * @desc description + * @param [string] $value [条件值] + * @param [array] $params [输入参数] + */ + public function WhereValueUserInfo($value, $params = []) + { + if(!empty($value)) + { + // 获取用户 id + $ids = Db::name('User')->where('username|nickname|mobile|email', 'like', '%'.$value.'%')->column('id'); + + // 避免空条件造成无效的错觉 + return empty($ids) ? [0] : $ids; + } + return $value; + } +} +?> \ No newline at end of file diff --git a/app/admin/form/Goodsspectemplate.php b/app/admin/form/Goodsspectemplate.php new file mode 100644 index 000000000..49e52aeee --- /dev/null +++ b/app/admin/form/Goodsspectemplate.php @@ -0,0 +1,167 @@ +[['pid', '=', 0]]]); + $this->goods_category_list = empty($res) ? [] : array_column($res, 'name', 'id'); + } + + /** + * 入口 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-06-18 + * @desc description + * @param [array] $params [输入参数] + */ + public function Run($params = []) + { + return [ + // 基础配置 + 'base' => [ + 'key_field' => 'id', + 'status_field' => 'is_enable', + 'is_search' => 1, + 'is_delete' => 1, + 'delete_url' => MyUrl('admin/goodsspectemplate/delete'), + 'delete_key' => 'ids', + ], + // 表单配置 + 'form' => [ + [ + 'view_type' => 'checkbox', + 'is_checked' => 0, + 'checked_text' => '反选', + 'not_checked_text' => '全选', + 'align' => 'center', + 'width' => 80, + ], + [ + 'label' => '商品分类', + 'view_type' => 'field', + 'view_key' => 'category_id', + '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, + ], + ], + [ + 'label' => '名称', + 'view_type' => 'field', + 'view_key' => 'name', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'input', + 'where_type' => 'like', + ], + ], + [ + 'label' => '是否启用', + 'view_type' => 'status', + 'view_key' => 'is_enable', + 'post_url' => MyUrl('admin/goodsspectemplate/statusupdate'), + 'is_form_su' => 1, + 'align' => 'center', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'select', + 'where_type' => 'in', + 'data' => MyConst('common_is_enable_list'), + 'data_key' => 'id', + 'data_name' => 'name', + 'is_multiple' => 1, + ], + ], + [ + 'label' => '规格值', + 'view_type' => 'field', + 'view_key' => 'content', + 'grid_size' => 'sm', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'input', + 'where_type' => 'like', + ], + ], + [ + 'label' => '创建时间', + 'view_type' => 'field', + 'view_key' => 'add_time', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'datetime', + ], + ], + [ + 'label' => '更新时间', + 'view_type' => 'field', + 'view_key' => 'upd_time', + 'is_sort' => 1, + 'search_config' => [ + 'form_type' => 'datetime', + ], + ], + [ + 'label' => '操作', + 'view_type' => 'operate', + 'view_key' => 'goodsspectemplate/module/operate', + 'align' => 'center', + 'fixed' => 'right', + ], + ], + // 数据配置 + 'data' => [ + 'table_name' => 'GoodsSpecTemplate', + 'data_handle' => 'GoodsSpecService::GoodsSpecTemplateListHandle', + 'is_page' => 1, + 'data_params' => [ + 'is_public' => 0, + 'user_type' => 'admin', + ], + ], + ]; + } +} +?> \ No newline at end of file diff --git a/app/admin/view/default/goods/save_info.html b/app/admin/view/default/goods/save_info.html index db32d7013..98377c21d 100755 --- a/app/admin/view/default/goods/save_info.html +++ b/app/admin/view/default/goods/save_info.html @@ -206,15 +206,15 @@
- 快捷操作 + 商品参数模板
+ + {{if !empty($goods_spec_template_list)}} + {{foreach $goods_spec_template_list as $v}} + + {{/foreach}} + {{/if}} + +
+ + 批量添加规格 生成规格
diff --git a/app/admin/view/default/goodscart/detail.html b/app/admin/view/default/goodscart/detail.html new file mode 100644 index 000000000..06eeee457 --- /dev/null +++ b/app/admin/view/default/goodscart/detail.html @@ -0,0 +1,2 @@ + +{{extend name="public/module/detail" /}} \ No newline at end of file diff --git a/app/admin/view/default/goodscart/index.html b/app/admin/view/default/goodscart/index.html new file mode 100755 index 000000000..907d6eab9 --- /dev/null +++ b/app/admin/view/default/goodscart/index.html @@ -0,0 +1,2 @@ + +{{extend name="public/module/form" /}} \ No newline at end of file diff --git a/app/admin/view/default/goodscart/module/goods.html b/app/admin/view/default/goodscart/module/goods.html new file mode 100644 index 000000000..e4376f695 --- /dev/null +++ b/app/admin/view/default/goodscart/module/goods.html @@ -0,0 +1,18 @@ + +{{if !empty($module_data)}} +
+ + + + {{$module_data.title}} + {{if !empty($module_data['simple_desc'])}} +

{{$module_data.simple_desc}}

+ {{/if}} +
+
+ {{if !empty($module_data['spec_text'])}} + {{$module_data.spec_text}} + {{/if}} + x{{$module_data.stock}} +
+{{/if}} \ No newline at end of file diff --git a/app/admin/view/default/goodscart/module/operate.html b/app/admin/view/default/goodscart/module/operate.html new file mode 100644 index 000000000..17e9497c2 --- /dev/null +++ b/app/admin/view/default/goodscart/module/operate.html @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/admin/view/default/goodsparamstemplate/index.html b/app/admin/view/default/goodsparamstemplate/index.html index 4f8c107e5..0d46bcd28 100755 --- a/app/admin/view/default/goodsparamstemplate/index.html +++ b/app/admin/view/default/goodsparamstemplate/index.html @@ -3,7 +3,7 @@ {{block name="form_operate_top"}} - 新增 + {__block__} {{/block}} \ No newline at end of file diff --git a/app/admin/view/default/goodsparamstemplate/module/operate.html b/app/admin/view/default/goodsparamstemplate/module/operate.html index 3b1a17635..d6591cf7a 100644 --- a/app/admin/view/default/goodsparamstemplate/module/operate.html +++ b/app/admin/view/default/goodsparamstemplate/module/operate.html @@ -3,10 +3,10 @@ 详情 - + +
+
+ + +
diff --git a/app/admin/view/default/goodsspectemplate/detail.html b/app/admin/view/default/goodsspectemplate/detail.html new file mode 100644 index 000000000..06eeee457 --- /dev/null +++ b/app/admin/view/default/goodsspectemplate/detail.html @@ -0,0 +1,2 @@ + +{{extend name="public/module/detail" /}} \ No newline at end of file diff --git a/app/admin/view/default/goodsspectemplate/index.html b/app/admin/view/default/goodsspectemplate/index.html new file mode 100755 index 000000000..e9595885d --- /dev/null +++ b/app/admin/view/default/goodsspectemplate/index.html @@ -0,0 +1,9 @@ + +{{extend name="public/module/form" /}} + + +{{block name="form_operate_top"}} + + + {__block__} +{{/block}} \ No newline at end of file diff --git a/app/admin/view/default/goodsspectemplate/module/operate.html b/app/admin/view/default/goodsspectemplate/module/operate.html new file mode 100644 index 000000000..1c98fa3c8 --- /dev/null +++ b/app/admin/view/default/goodsspectemplate/module/operate.html @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/admin/view/default/goodsspectemplate/save_info.html b/app/admin/view/default/goodsspectemplate/save_info.html new file mode 100755 index 000000000..9bb087916 --- /dev/null +++ b/app/admin/view/default/goodsspectemplate/save_info.html @@ -0,0 +1,69 @@ +{{include file="public/header" /}} + + +
+
+ +
+
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ + + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}} +
+ plugins_view_admin_goods_spec_template_save +
+ {{/if}} + {{if !empty($plugins_view_admin_goods_spec_template_save_data) and is_array($plugins_view_admin_goods_spec_template_save_data)}} +
+ +
+ {{foreach $plugins_view_admin_goods_spec_template_save_data as $hook}} + {{if is_string($hook) or is_int($hook)}} + {{$hook|raw}} + {{/if}} + {{/foreach}} +
+
+ {{/if}} + + +
+
+ + +
+
+
+ +
+
+ + + +{{include file="public/footer" /}} + \ No newline at end of file diff --git a/app/api/controller/Cart.php b/app/api/controller/Cart.php index c5239d2c1..3aece075d 100755 --- a/app/api/controller/Cart.php +++ b/app/api/controller/Cart.php @@ -12,7 +12,7 @@ namespace app\api\controller; use app\service\ApiService; use app\service\SystemBaseService; -use app\service\BuyService; +use app\service\GoodsCartService; /** * 购物车 @@ -48,10 +48,10 @@ class Cart extends Common */ public function Index() { - $ret = BuyService::CartList(['user'=>$this->user]); + $ret = GoodsCartService::GoodsCartList(['user'=>$this->user]); $result = [ 'data' => $ret['data'], - 'common_cart_total' => BuyService::UserCartTotal(['user'=>$this->user]), + 'common_cart_total' => GoodsCartService::UserGoodsCartTotal(['user'=>$this->user]), ]; return ApiService::ApiDataReturn(SystemBaseService::DataReturn($result)); @@ -69,7 +69,7 @@ class Cart extends Common { $params = $this->data_post; $params['user'] = $this->user; - return ApiService::ApiDataReturn(BuyService::CartSave($params)); + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartSave($params)); } /** @@ -84,7 +84,7 @@ class Cart extends Common { $params = $this->data_post; $params['user'] = $this->user; - return ApiService::ApiDataReturn(BuyService::CartDelete($params)); + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartDelete($params)); } /** @@ -99,7 +99,7 @@ class Cart extends Common { $params = $this->data_post; $params['user'] = $this->user; - return ApiService::ApiDataReturn(BuyService::CartStock($params)); + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartStock($params)); } } ?> \ No newline at end of file diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 61db7c983..69894873b 100755 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -11,6 +11,7 @@ namespace app\api\controller; use app\service\ApiService; +use app\service\AppService; use app\service\SystemBaseService; use app\service\GoodsService; use app\service\BuyService; @@ -18,7 +19,7 @@ use app\service\GoodsCommentsService; use app\service\ResourcesService; use app\service\GoodsFavorService; use app\service\GoodsBrowseService; -use app\service\AppService; +use app\service\GoodsCartService; /** * 商品 @@ -122,7 +123,7 @@ class Goods extends Common // 数据返回 $result = [ 'goods' => $goods, - 'common_cart_total' => BuyService::UserCartTotal(['user'=>$this->user]), + 'common_cart_total' => GoodsCartService::UserGoodsCartTotal(['user'=>$this->user]), 'buy_button' => $buy_button, 'middle_tabs_nav' => $middle_tabs_nav, 'nav_more_list' => $nav_more_list, diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 7700309db..74f7e0bcf 100755 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -21,6 +21,7 @@ use app\service\ArticleService; use app\service\MessageService; use app\service\AppService; use app\service\PluginsService; +use app\service\GoodsCartService; /** * 首页 @@ -62,7 +63,7 @@ class Index extends Common } // 购物车数量 - $common_cart_total = BuyService::UserCartTotal(['user'=>$this->user]); + $common_cart_total = GoodsCartService::UserGoodsCartTotal(['user'=>$this->user]); // 未读消息总数 $params = ['user'=>$this->user, 'is_more'=>1, 'is_read'=>0]; diff --git a/app/api/controller/User.php b/app/api/controller/User.php index a0f522717..099644919 100755 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -22,6 +22,7 @@ use app\service\GoodsFavorService; use app\service\GoodsBrowseService; use app\service\IntegralService; use app\service\AppMiniUserService; +use app\service\GoodsCartService; /** * 用户 @@ -271,7 +272,7 @@ class User extends Common 'user_goods_browse_count' => $user_goods_browse_count, 'common_message_total' => $common_message_total, 'navigation' => AppCenterNavService::AppCenterNav(), - 'common_cart_total' => BuyService::UserCartTotal(['user'=>$this->user]), + 'common_cart_total' => GoodsCartService::UserGoodsCartTotal(['user'=>$this->user]), ); // 返回数据 diff --git a/app/index/controller/Cart.php b/app/index/controller/Cart.php index 2672b4aec..1495a891d 100755 --- a/app/index/controller/Cart.php +++ b/app/index/controller/Cart.php @@ -12,7 +12,7 @@ namespace app\index\controller; use app\service\ApiService; use app\service\SeoService; -use app\service\BuyService; +use app\service\GoodsCartService; /** * 购物车 @@ -49,12 +49,12 @@ class Cart extends Common public function Index() { // 购物车列表 - $cart_list = BuyService::CartList(['user'=>$this->user]); + $cart_list = GoodsCartService::GoodsCartList(['user'=>$this->user]); // 基础信息 $base = [ 'total_price' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'total_price')), - 'buy_count' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'stock')), + 'buy_count' => empty($cart_list['data']) ? 0 : array_sum(array_column($cart_list['data'], 'stock')), ]; // 数据赋值 @@ -85,7 +85,7 @@ class Cart extends Common $params = $this->data_post; $params['user'] = $this->user; - return ApiService::ApiDataReturn(BuyService::CartSave($params)); + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartSave($params)); } /** @@ -106,7 +106,7 @@ class Cart extends Common $params = $this->data_post; $params['user'] = $this->user; - return ApiService::ApiDataReturn(BuyService::CartDelete($params)); + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartDelete($params)); } /** @@ -127,7 +127,7 @@ class Cart extends Common $params = $this->data_post; $params['user'] = $this->user; - return ApiService::ApiDataReturn(BuyService::CartStock($params)); + return ApiService::ApiDataReturn(GoodsCartService::GoodsCartStock($params)); } } ?> \ No newline at end of file diff --git a/app/index/controller/User.php b/app/index/controller/User.php index 3173d98fc..3a81f26f1 100755 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -15,12 +15,12 @@ use app\service\SystemService; use app\service\OrderService; use app\service\GoodsService; use app\service\UserService; -use app\service\BuyService; use app\service\SeoService; use app\service\MessageService; use app\service\NavigationService; use app\service\GoodsBrowseService; use app\service\GoodsFavorService; +use app\service\GoodsCartService; /** * 用户 @@ -134,7 +134,7 @@ class User extends Common $assign['order_list'] = $order['data']; // 获取购物车 - $cart_list = BuyService::CartList(['user'=>$this->user]); + $cart_list = GoodsCartService::GoodsCartList(['user'=>$this->user]); $assign['cart_list'] = $cart_list['data']; // 收藏商品 diff --git a/app/service/AdminPowerService.php b/app/service/AdminPowerService.php index b1431ba51..283a747f5 100755 --- a/app/service/AdminPowerService.php +++ b/app/service/AdminPowerService.php @@ -132,18 +132,12 @@ class AdminPowerService $data['add_time'] = time(); if(Db::name('Power')->insertGetId($data) > 0) { - // 清除用户权限数据 - self::PowerCacheDelete(); - return DataReturn(MyLang('common.insert_success'), 0); } return DataReturn(MyLang('common.insert_fail'), -100); } else { if(Db::name('Power')->where(['id'=>intval($params['id'])])->update($data) !== false) { - // 清除用户权限数据 - self::PowerCacheDelete(); - return DataReturn(MyLang('common.update_success'), 0); } return DataReturn(MyLang('common.update_fail'), -100); diff --git a/app/service/BuyService.php b/app/service/BuyService.php index 56e8c9465..705b5cb07 100755 --- a/app/service/BuyService.php +++ b/app/service/BuyService.php @@ -12,8 +12,9 @@ namespace app\service; use think\facade\Db; use app\service\SystemBaseService; -use app\service\GoodsService; use app\service\UserService; +use app\service\GoodsService; +use app\service\GoodsCartService; use app\service\UserAddressService; use app\service\ResourcesService; use app\service\PaymentService; @@ -31,488 +32,6 @@ use app\service\OrderCurrencyService; */ class BuyService { - /** - * 购物车添加/更新 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-08-29 - * @desc description - * @param [array] $params [输入参数] - */ - public static function CartSave($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'goods_id', - 'error_msg' => '商品id有误', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'stock', - 'error_msg' => '购买数量有误', - ], - [ - 'checked_type' => 'min', - 'key_name' => 'stock', - 'checked_data' => 1, - 'error_msg' => '购买数量有误', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 查询用户状态是否正常 - $ret = UserService::UserStatusCheck('id', $params['user']['id']); - if($ret['code'] != 0) - { - return $ret; - } - - // 获取商品 - $goods_id = intval($params['goods_id']); - $goods = Db::name('Goods')->where(['id'=>$goods_id, 'is_shelves'=>1, 'is_delete_time'=>0])->find(); - if(empty($goods)) - { - return DataReturn('商品不存在或已删除', -2); - } - - // 无封面图片 - if(empty($goods['images'])) - { - $goods['images'] = ResourcesService::AttachmentPathHandle(GoodsService::GoodsImagesCoverHandle($goods_id)); - } - - // 是否支持购物车操作 - $ret = GoodsService::IsGoodsSiteTypeConsistent($goods_id, $goods['site_type']); - if($ret['code'] != 0) - { - return $ret; - } - - // 规格处理 - $spec = self::GoodsSpecificationsHandle($params); - - // 获取商品基础信息 - $spec_params = array_merge($params, [ - 'id' => $goods_id, - 'spec' => $spec, - ]); - $goods_base = GoodsService::GoodsSpecDetail($spec_params); - if($goods_base['code'] != 0) - { - return $goods_base; - } - - // 是否存在规格 - if(!empty($spec)) - { - // 获取商品规格图片 - $images = self::BuyGoodsSpecImages($goods_id, $spec); - if(!empty($images)) - { - $goods['images'] = $images; - $goods['images_old'] = ResourcesService::AttachmentPathViewHandle($images); - } - - // 规格库存赋值 - $goods['inventory'] = $goods_base['data']['spec_base']['inventory']; - } - - // 数量 - $stock = ($goods['buy_max_number'] > 0 && $params['stock'] > $goods['buy_max_number']) ? $goods['buy_max_number'] : $params['stock']; - - // 库存 - if($stock > $goods['inventory']) - { - return DataReturn('库存不足', -1); - } - - // 添加购物车 - $data = [ - 'user_id' => $params['user']['id'], - 'goods_id' => $goods_id, - 'title' => $goods['title'], - 'images' => $goods['images'], - 'original_price'=> $goods_base['data']['spec_base']['original_price'], - 'price' => $goods_base['data']['spec_base']['price'], - 'stock' => $stock, - 'spec' => empty($spec) ? '' : json_encode($spec, JSON_UNESCAPED_UNICODE), - ]; - - // 存在则更新 - $where = ['user_id'=>$data['user_id'], 'goods_id'=>$data['goods_id'], 'spec'=>$data['spec']]; - $temp = Db::name('Cart')->where($where)->find(); - if(empty($temp)) - { - $data['add_time'] = time(); - if(Db::name('Cart')->insertGetId($data) > 0) - { - return DataReturn(MyLang('common.join_success'), 0, self::UserCartTotal($params)); - } - } else { - $data['upd_time'] = time(); - $data['stock'] += $temp['stock']; - if($data['stock'] > $goods['inventory']) - { - $data['stock'] = $goods['inventory']; - } - if($goods['buy_max_number'] > 0 && $data['stock'] > $goods['buy_max_number']) - { - $data['stock'] = $goods['buy_max_number']; - } - if(Db::name('Cart')->where($where)->update($data)) - { - return DataReturn(MyLang('common.join_success'), 0, self::UserCartTotal($params)); - } - } - - return DataReturn(MyLang('common.join_fail'), -100); - } - - /** - * 商品规格解析 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-09-21 - * @desc description - * @param [array] $params [输入参数] - */ - public static function GoodsSpecificationsHandle($params = []) - { - $spec = ''; - if(!empty($params['spec'])) - { - if(!is_array($params['spec'])) - { - $spec = json_decode(htmlspecialchars_decode($params['spec']), true); - } else { - $spec = $params['spec']; - } - } - return empty($spec) ? '' : $spec; - } - - /** - * 获取购物车列表 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-08-29 - * @desc description - * @param [array] $params [输入参数] - */ - public static function CartList($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 基础参数 - $where = (!empty($params['where']) && is_array($params['where'])) ? $params['where'] : []; - $where[] = ['c.user_id', '=', $params['user']['id']]; - $field = 'c.*, g.inventory_unit, g.is_shelves, g.is_delete_time, g.buy_min_number, g.buy_max_number, g.model, g.site_type'; - - // 购物车列表读取前钩子 - $hook_name = 'plugins_service_cart_goods_list_begin'; - MyEventTrigger($hook_name, [ - 'hook_name' => $hook_name, - 'is_backend' => true, - 'params' => &$params, - 'where' => &$where, - 'field' => &$field, - ]); - - // 获取购物车数据 - $data = Db::name('Cart')->alias('c')->leftJoin('goods g', 'g.id=c.goods_id')->where($where)->field($field)->order('c.id desc')->select()->toArray(); - - // 数据处理 - $data = self::CartListDataHandle($data, $params); - return DataReturn(MyLang('common.operate_success'), 0, $data); - } - - /** - * 购物车列表数据处理 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2022-04-05 - * @desc description - * @param [array] $data [购物车数据] - * @param [array] $params [输入参数] - */ - public static function CartListDataHandle($data, $params = []) - { - if(!empty($data)) - { - // 商品处理 - $res = GoodsService::GoodsDataHandle($data, ['data_key_field'=>'goods_id']); - $data = $res['data']; - foreach($data as &$v) - { - // 规格 - $v['spec'] = empty($v['spec']) ? null : json_decode($v['spec'], true); - - // 获取商品基础信息 - $spec_params = array_merge($params, [ - 'id' => $v['goods_id'], - 'spec' => $v['spec'], - 'stock' => $v['stock'], - ]); - $goods_base = GoodsService::GoodsSpecDetail($spec_params); - $v['is_invalid'] = 0; - if($goods_base['code'] == 0) - { - $v['inventory'] = $goods_base['data']['spec_base']['inventory']; - $v['price'] = $goods_base['data']['spec_base']['price']; - $v['original_price'] = $goods_base['data']['spec_base']['original_price']; - $v['spec_weight'] = $goods_base['data']['spec_base']['weight']; - $v['spec_volume'] = $goods_base['data']['spec_base']['volume']; - $v['spec_coding'] = $goods_base['data']['spec_base']['coding']; - $v['spec_barcode'] = $goods_base['data']['spec_base']['barcode']; - $v['extends'] = $goods_base['data']['spec_base']['extends']; - } else { - $v['is_invalid'] = 1; - $v['inventory'] = 0; - $v['spec_weight'] = 0; - $v['spec_volume'] = 0; - $v['spec_coding'] = ''; - $v['spec_barcode'] = ''; - $v['extends'] = ''; - } - - // 基础信息 - $v['total_price'] = PriceNumberFormat($v['stock']* $v['price']); - $v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number']; - - // 错误处理 - $v['is_error'] = 0; - $v['error_msg'] = ''; - if($v['is_delete_time'] != 0) - { - $v['is_error'] = 1; - $v['error_msg'] = '已作废'; - } - if(empty($v['error_msg']) && $v['is_invalid'] == 1) - { - $v['is_error'] = 1; - $v['error_msg'] = '已失效'; - } - if(empty($v['error_msg']) && $v['is_shelves'] != 1) - { - $v['is_error'] = 1; - $v['error_msg'] = '已下架'; - } - if(empty($v['error_msg']) && $v['inventory'] <= 0) - { - $v['is_error'] = 1; - $v['error_msg'] = '没货了'; - } - if(empty($v['error_msg'])) - { - $ret = GoodsService::IsGoodsSiteTypeConsistent($v['goods_id'], $v['site_type']); - if($ret['code'] != 0) - { - $v['is_error'] = 1; - $v['error_msg'] = $ret['msg']; - } - } - } - } - return $data; - } - - /** - * 购物车删除 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-09-14 - * @desc description - * @param [array] $params [输入参数] - */ - public static function CartDelete($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'id', - 'error_msg' => '删除数据id有误', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 查询用户状态是否正常 - $ret = UserService::UserStatusCheck('id', $params['user']['id']); - if($ret['code'] != 0) - { - return $ret; - } - - // 删除 - $where = [ - 'id' => is_array($params['id']) ? $params['id'] : explode(',', $params['id']), - 'user_id' => $params['user']['id'] - ]; - if(Db::name('Cart')->where($where)->delete()) - { - return DataReturn(MyLang('common.delete_success'), 0, self::UserCartTotal($params)); - } - return DataReturn('删除失败或资源不存在', -100); - } - - /** - * 购物车数量保存 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-09-14 - * @desc description - * @param [array] $params [输入参数] - */ - public static function CartStock($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'id', - 'error_msg' => '数据id有误', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'goods_id', - 'error_msg' => '商品id有误', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'stock', - 'error_msg' => '购买数量有误', - ], - [ - 'checked_type' => 'min', - 'key_name' => 'stock', - 'checked_data' => 1, - 'error_msg' => '购买数量有误', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 查询用户状态是否正常 - $ret = UserService::UserStatusCheck('id', $params['user']['id']); - if($ret['code'] != 0) - { - return $ret; - } - - // 条件 - $where = [ - 'id' => intval($params['id']), - 'goods_id' => intval($params['goods_id']), - 'user_id' => intval($params['user']['id']), - ]; - - // 数量 - $stock = intval($params['stock']); - - // 获取购物车数据 - $data = Db::name('Cart')->where($where)->field('goods_id,title,price,stock,spec')->find(); - if(empty($data)) - { - return DataReturn('请先加入购物车', -1); - } - $data['stock'] = $stock; - $data['spec'] = empty($data['spec']) ? null : json_decode($data['spec'], true); - - // 商品校验 - $ret = self::BuyGoodsCheck(['goods'=>[$data]]); - if($ret['code'] != 0) - { - return $ret; - } - - // 更新数据 - $upd_data = [ - 'stock' => $stock, - 'upd_time' => time(), - ]; - if(Db::name('Cart')->where($where)->update($upd_data)) - { - // 获取商品基础信息、更新商品价格信息 - $spec_params = array_merge($params, [ - 'id' => $data['goods_id'], - 'spec' => $data['spec'], - 'stock' => $data['stock'], - ]); - $goods_base = GoodsService::GoodsSpecDetail($spec_params); - if($goods_base['code'] == 0) - { - $data['price'] = $goods_base['data']['spec_base']['price']; - $data['original_price'] = $goods_base['data']['spec_base']['original_price']; - } - - // 增加价格总计 - $data['total_price'] = PriceNumberFormat($data['stock']*$data['price']); - - // 购物车更新成功钩子 - $hook_name = 'plugins_service_cart_update_success'; - $ret = EventReturnHandle(MyEventTrigger($hook_name, [ - 'hook_name' => $hook_name, - 'is_backend' => true, - 'params' => $params, - 'data' => &$data, - 'goods_id' => $params['goods_id'] - ])); - if(isset($ret['code']) && $ret['code'] != 0) - { - return $ret; - } - - return DataReturn(MyLang('common.update_success'), 0, $data); - } - return DataReturn(MyLang('common.update_fail'), -100); - } - /** * 下订单 - 正常购买 * @author Devil @@ -616,6 +135,30 @@ class BuyService return $ret; } + /** + * 商品规格解析 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-21 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsSpecificationsHandle($params = []) + { + $spec = ''; + if(!empty($params['spec'])) + { + if(!is_array($params['spec'])) + { + $spec = json_decode(htmlspecialchars_decode($params['spec']), true); + } else { + $spec = $params['spec']; + } + } + return empty($spec) ? '' : $spec; + } + /** * 下订单 - 购物车 * @author Devil @@ -652,7 +195,7 @@ class BuyService ['g.is_shelves', '=', 1], ['c.id', 'in', explode(',', $params['ids'])], ]; - return self::CartList($params); + return GoodsCartService::GoodsCartList($params); } /** @@ -1637,64 +1180,6 @@ class BuyService return DataReturn('订单地址添加失败', -1); } - /** - * 购物车总数 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-09-29 - * @desc description - * @param [array] $where [条件] - */ - public static function CartTotal($where = []) - { - return (int) Db::name('Cart')->where($where)->count(); - } - - /** - * 用户购物车总数 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-09-29 - * @desc description - * @param [array] $params [输入参数] - * @return [int|string] [超过99则返回 99+] - */ - public static function UserCartTotal($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return 0; - } - - // 条件 - $where = [ - ['user_id', '=', $params['user']['id']] - ]; - - // 购物车总数读取前钩子 - $hook_name = 'plugins_service_user_cart_total_begin'; - MyEventTrigger($hook_name, [ - 'hook_name' => $hook_name, - 'is_backend' => true, - 'params' => $params, - 'where' => &$where, - ]); - - $total = self::CartTotal($where); - return ($total > 99) ? '99+' : $total; - } - /** * 单个订单支付前校验 * @author Devil diff --git a/app/service/GoodsCartService.php b/app/service/GoodsCartService.php new file mode 100644 index 000000000..fb9bf3938 --- /dev/null +++ b/app/service/GoodsCartService.php @@ -0,0 +1,572 @@ + 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 基础参数 + $where = (!empty($params['where']) && is_array($params['where'])) ? $params['where'] : []; + $where[] = ['c.user_id', '=', $params['user']['id']]; + $field = 'c.*, g.inventory_unit, g.is_shelves, g.is_delete_time, g.buy_min_number, g.buy_max_number, g.model, g.site_type'; + + // 购物车列表读取前钩子 + $hook_name = 'plugins_service_cart_goods_list_begin'; + MyEventTrigger($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => &$params, + 'where' => &$where, + 'field' => &$field, + ]); + + // 获取购物车数据 + $data = Db::name('Cart')->alias('c')->leftJoin('goods g', 'g.id=c.goods_id')->where($where)->field($field)->order('c.id desc')->select()->toArray(); + if(!empty($data)) + { + // 商品处理 + $res = GoodsService::GoodsDataHandle($data, ['data_key_field'=>'goods_id']); + $data = $res['data']; + foreach($data as &$v) + { + // 规格 + $v['spec'] = empty($v['spec']) ? null : json_decode($v['spec'], true); + + // 获取商品基础信息 + $spec_params = array_merge($params, [ + 'id' => $v['goods_id'], + 'spec' => $v['spec'], + 'stock' => $v['stock'], + ]); + $goods_base = GoodsService::GoodsSpecDetail($spec_params); + $v['is_invalid'] = 0; + if($goods_base['code'] == 0) + { + $v['inventory'] = $goods_base['data']['spec_base']['inventory']; + $v['price'] = $goods_base['data']['spec_base']['price']; + $v['original_price'] = $goods_base['data']['spec_base']['original_price']; + $v['spec_weight'] = $goods_base['data']['spec_base']['weight']; + $v['spec_volume'] = $goods_base['data']['spec_base']['volume']; + $v['spec_coding'] = $goods_base['data']['spec_base']['coding']; + $v['spec_barcode'] = $goods_base['data']['spec_base']['barcode']; + $v['extends'] = $goods_base['data']['spec_base']['extends']; + } else { + $v['is_invalid'] = 1; + $v['inventory'] = 0; + $v['spec_weight'] = 0; + $v['spec_volume'] = 0; + $v['spec_coding'] = ''; + $v['spec_barcode'] = ''; + $v['extends'] = ''; + } + + // 基础信息 + $v['total_price'] = PriceNumberFormat($v['stock']* $v['price']); + $v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number']; + + // 错误处理 + $v['is_error'] = 0; + $v['error_msg'] = ''; + if($v['is_delete_time'] != 0) + { + $v['is_error'] = 1; + $v['error_msg'] = '已作废'; + } + if(empty($v['error_msg']) && $v['is_invalid'] == 1) + { + $v['is_error'] = 1; + $v['error_msg'] = '已失效'; + } + if(empty($v['error_msg']) && $v['is_shelves'] != 1) + { + $v['is_error'] = 1; + $v['error_msg'] = '已下架'; + } + if(empty($v['error_msg']) && $v['inventory'] <= 0) + { + $v['is_error'] = 1; + $v['error_msg'] = '没货了'; + } + if(empty($v['error_msg'])) + { + $ret = GoodsService::IsGoodsSiteTypeConsistent($v['goods_id'], $v['site_type']); + if($ret['code'] != 0) + { + $v['is_error'] = 1; + $v['error_msg'] = $ret['msg']; + } + } + } + } + return DataReturn(MyLang('common.operate_success'), 0, $data); + } + + /** + * 列表数据处理 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-08-01 + * @desc description + * @param [array] $data [数据列表] + * @param [array] $params [输入参数] + */ + public static function GoodsCartListHandle($data, $params = []) + { + if(!empty($data)) + { + // 商品数据处理 + $ret = GoodsService::GoodsDataHandle($data, ['data_key_field'=>'goods_id']); + $data = $ret['data']; + + // 是否公共读取 + $is_public = (isset($params['is_public']) && $params['is_public'] == 0) ? 0 : 1; + $users = []; + foreach($data as &$v) + { + // 用户信息 + if(isset($v['user_id']) && $is_public == 0) + { + if(!array_key_exists($v['user_id'], $users)) + { + $users[$v['user_id']] = UserService::GetUserViewInfo($v['user_id']); + } + $v['user'] = $users[$v['user_id']]; + } + + // 规格 + $v['spec_text'] = null; + if(!empty($v['spec'])) + { + $v['spec'] = json_decode($v['spec'], true); + if(!empty($v['spec']) && is_array($v['spec'])) + { + $v['spec_text'] = implode(',', array_map(function($spec) + { + return $spec['type'].':'.$spec['value']; + }, $v['spec'])); + } + } else { + $v['spec'] = null; + } + } + } + return $data; + } + + /** + * 购物车添加/更新 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-29 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsCartSave($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'goods_id', + 'error_msg' => '商品id有误', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'stock', + 'error_msg' => '购买数量有误', + ], + [ + 'checked_type' => 'min', + 'key_name' => 'stock', + 'checked_data' => 1, + 'error_msg' => '购买数量有误', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 查询用户状态是否正常 + $ret = UserService::UserStatusCheck('id', $params['user']['id']); + if($ret['code'] != 0) + { + return $ret; + } + + // 获取商品 + $goods_id = intval($params['goods_id']); + $goods = Db::name('Goods')->where(['id'=>$goods_id, 'is_shelves'=>1, 'is_delete_time'=>0])->find(); + if(empty($goods)) + { + return DataReturn('商品不存在或已删除', -2); + } + + // 无封面图片 + if(empty($goods['images'])) + { + $goods['images'] = ResourcesService::AttachmentPathHandle(GoodsService::GoodsImagesCoverHandle($goods_id)); + } + + // 是否支持购物车操作 + $ret = GoodsService::IsGoodsSiteTypeConsistent($goods_id, $goods['site_type']); + if($ret['code'] != 0) + { + return $ret; + } + + // 规格处理 + $spec = BuyService::GoodsSpecificationsHandle($params); + + // 获取商品基础信息 + $spec_params = array_merge($params, [ + 'id' => $goods_id, + 'spec' => $spec, + ]); + $goods_base = GoodsService::GoodsSpecDetail($spec_params); + if($goods_base['code'] != 0) + { + return $goods_base; + } + + // 是否存在规格 + if(!empty($spec)) + { + // 获取商品规格图片 + $images = BuyService::BuyGoodsSpecImages($goods_id, $spec); + if(!empty($images)) + { + $goods['images'] = $images; + $goods['images_old'] = ResourcesService::AttachmentPathViewHandle($images); + } + + // 规格库存赋值 + $goods['inventory'] = $goods_base['data']['spec_base']['inventory']; + } + + // 数量 + $stock = ($goods['buy_max_number'] > 0 && $params['stock'] > $goods['buy_max_number']) ? $goods['buy_max_number'] : $params['stock']; + + // 库存 + if($stock > $goods['inventory']) + { + return DataReturn('库存不足', -1); + } + + // 添加购物车 + $data = [ + 'user_id' => $params['user']['id'], + 'goods_id' => $goods_id, + 'title' => $goods['title'], + 'images' => $goods['images'], + 'original_price'=> $goods_base['data']['spec_base']['original_price'], + 'price' => $goods_base['data']['spec_base']['price'], + 'stock' => $stock, + 'spec' => empty($spec) ? '' : json_encode($spec, JSON_UNESCAPED_UNICODE), + ]; + + // 存在则更新 + $where = ['user_id'=>$data['user_id'], 'goods_id'=>$data['goods_id'], 'spec'=>$data['spec']]; + $temp = Db::name('Cart')->where($where)->find(); + if(empty($temp)) + { + $data['add_time'] = time(); + if(Db::name('Cart')->insertGetId($data) > 0) + { + return DataReturn(MyLang('common.join_success'), 0, self::UserGoodsCartTotal($params)); + } + } else { + $data['upd_time'] = time(); + $data['stock'] += $temp['stock']; + if($data['stock'] > $goods['inventory']) + { + $data['stock'] = $goods['inventory']; + } + if($goods['buy_max_number'] > 0 && $data['stock'] > $goods['buy_max_number']) + { + $data['stock'] = $goods['buy_max_number']; + } + if(Db::name('Cart')->where($where)->update($data)) + { + return DataReturn(MyLang('common.join_success'), 0, self::UserGoodsCartTotal($params)); + } + } + return DataReturn(MyLang('common.join_fail'), -100); + } + + /** + * 购物车数量保存 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-14 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsCartStock($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'id', + 'error_msg' => '数据id有误', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'goods_id', + 'error_msg' => '商品id有误', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'stock', + 'error_msg' => '购买数量有误', + ], + [ + 'checked_type' => 'min', + 'key_name' => 'stock', + 'checked_data' => 1, + 'error_msg' => '购买数量有误', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 查询用户状态是否正常 + $ret = UserService::UserStatusCheck('id', $params['user']['id']); + if($ret['code'] != 0) + { + return $ret; + } + + // 条件 + $where = [ + 'id' => intval($params['id']), + 'goods_id' => intval($params['goods_id']), + 'user_id' => intval($params['user']['id']), + ]; + + // 数量 + $stock = intval($params['stock']); + + // 获取购物车数据 + $data = Db::name('Cart')->where($where)->field('goods_id,title,price,stock,spec')->find(); + if(empty($data)) + { + return DataReturn('请先加入购物车', -1); + } + $data['stock'] = $stock; + $data['spec'] = empty($data['spec']) ? null : json_decode($data['spec'], true); + + // 商品校验 + $ret = self::BuyGoodsCheck(['goods'=>[$data]]); + if($ret['code'] != 0) + { + return $ret; + } + + // 更新数据 + $upd_data = [ + 'stock' => $stock, + 'upd_time' => time(), + ]; + if(Db::name('Cart')->where($where)->update($upd_data)) + { + // 获取商品基础信息、更新商品价格信息 + $spec_params = array_merge($params, [ + 'id' => $data['goods_id'], + 'spec' => $data['spec'], + 'stock' => $data['stock'], + ]); + $goods_base = GoodsService::GoodsSpecDetail($spec_params); + if($goods_base['code'] == 0) + { + $data['price'] = $goods_base['data']['spec_base']['price']; + $data['original_price'] = $goods_base['data']['spec_base']['original_price']; + } + + // 增加价格总计 + $data['total_price'] = PriceNumberFormat($data['stock']*$data['price']); + + // 购物车更新成功钩子 + $hook_name = 'plugins_service_cart_update_success'; + $ret = EventReturnHandle(MyEventTrigger($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data' => &$data, + 'goods_id' => $params['goods_id'] + ])); + if(isset($ret['code']) && $ret['code'] != 0) + { + return $ret; + } + + return DataReturn(MyLang('common.update_success'), 0, $data); + } + return DataReturn(MyLang('common.update_fail'), -100); + } + + /** + * 购物车总数 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-29 + * @desc description + * @param [array] $where [条件] + */ + public static function GoodsCartTotal($where = []) + { + return (int) Db::name('Cart')->where($where)->count(); + } + + /** + * 用户购物车总数 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-29 + * @desc description + * @param [array] $params [输入参数] + * @return [int|string] [超过99则返回 99+] + */ + public static function UserGoodsCartTotal($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return 0; + } + + // 条件 + $where = [ + ['user_id', '=', $params['user']['id']] + ]; + + // 购物车总数读取前钩子 + $hook_name = 'plugins_service_user_cart_total_begin'; + MyEventTrigger($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'where' => &$where, + ]); + + $total = self::GoodsCartTotal($where); + return ($total > 99) ? '99+' : $total; + } + + /** + * 商品购物车删除 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-14 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsCartDelete($params = []) + { + // 参数处理 + $ids = empty($params['ids']) ? (empty($params['id']) ? [] : $params['id']) : $params['ids']; + if(empty($ids)) + { + return DataReturn('操作id有误', -1); + } + // 是否数组 + if(!is_array($ids)) + { + $ids = explode(',', $ids); + } + + // 条件 + $where = [ + ['id', 'in', $ids], + ]; + + // 用户id + if(!empty($params['user'])) + { + $where[] = ['user_id', '=', $params['user']['id']]; + } + + // 删除 + if(Db::name('Cart')->where($where)->delete()) + { + return DataReturn(MyLang('common.delete_success'), 0, self::UserGoodsCartTotal($params)); + } + return DataReturn(MyLang('common.delete_fail'), -100); + } +} +?> \ No newline at end of file diff --git a/app/service/GoodsSpecService.php b/app/service/GoodsSpecService.php new file mode 100644 index 000000000..acbcee7c0 --- /dev/null +++ b/app/service/GoodsSpecService.php @@ -0,0 +1,262 @@ + 'empty', + 'key_name' => 'category_ids', + 'error_msg' => '请选择商品分类', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 获取分类下所有分类id + $data = []; + $ids = GoodsService::GoodsCategoryParentIds($params['category_ids']); + if(!empty($ids)) + { + $where = [ + ['category_id', 'in', $ids], + ['is_enable', '=', 1], + ]; + $data = self::GoodsSpecTemplateListHandle(Db::name('GoodsSpecTemplate')->where($where)->field('id,name,content')->order('id desc')->select()->toArray()); + } + return DataReturn(MyLang('common.operate_success'), 0, $data); + } + + /** + * 列表数据处理 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-08-01 + * @desc description + * @param [array] $data [数据列表] + * @param [array] $params [输入参数] + */ + public static function GoodsSpecTemplateListHandle($data, $params = []) + { + if(!empty($data)) + { + foreach($data as &$v) + { + // 时间 + if(array_key_exists('add_time', $v)) + { + $v['add_time'] = date('Y-m-d H:i:s', $v['add_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']); + } + } + } + return $data; + } + + /** + * 保存 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-12-18 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsSpecTemplateSave($params = []) + { + // 请求类型 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'category_id', + 'error_msg' => '请选择商品分类', + ], + [ + 'checked_type' => 'length', + 'key_name' => 'name', + 'checked_data' => '1,30', + 'error_msg' => '规格名称格式2~30个字符', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'content', + 'error_msg' => '请填写规格值', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 数据 + $data = [ + 'category_id' => intval($params['category_id']), + 'name' => $params['name'], + 'content' => $params['content'], + 'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0, + ]; + + // 保存处理钩子 + $hook_name = 'plugins_service_goods_spec_template_save_handle'; + $ret = EventReturnHandle(MyEventTrigger($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => &$params, + 'data' => &$data, + 'data_id' => isset($params['id']) ? intval($params['id']) : 0, + ])); + if(isset($ret['code']) && $ret['code'] != 0) + { + return $ret; + } + + // 捕获异常 + try { + // 添加/编辑 + if(empty($params['id'])) + { + $data['add_time'] = time(); + $template_id = Db::name('GoodsSpecTemplate')->insertGetId($data); + if($template_id <= 0) + { + throw new \Exception('添加失败'); + } + } else { + $data['upd_time'] = time(); + if(Db::name('GoodsSpecTemplate')->where(['id'=>intval($params['id'])])->update($data) === false) + { + throw new \Exception('更新失败'); + } else { + $template_id = $params['id']; + } + } + + // 完成 + return DataReturn(MyLang('common.operate_success'), 0); + } catch(\Exception $e) { + return DataReturn($e->getMessage(), -1); + } + } + + /** + * 删除 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-12-18 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsSpecTemplateDelete($params = []) + { + // 参数是否有误 + if(empty($params['ids'])) + { + return DataReturn('操作id有误', -1); + } + // 是否数组 + if(!is_array($params['ids'])) + { + $params['ids'] = explode(',', $params['ids']); + } + + // 捕获异常 + try { + // 模板删除 + if(!Db::name('GoodsSpecTemplate')->where(['id'=>$params['ids']])->delete()) + { + throw new \Exception('模板删除失败'); + } + + // 完成 + return DataReturn(MyLang('common.delete_success'), 0); + } catch(\Exception $e) { + return DataReturn($e->getMessage(), -1); + } + } + + /** + * 状态更新 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-12-18 + * @desc description + * @param [array] $params [输入参数] + */ + public static function GoodsSpecTemplateStatusUpdate($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'id', + 'error_msg' => '操作id有误', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'field', + 'error_msg' => '未指定操作字段', + ], + [ + 'checked_type' => 'in', + 'key_name' => 'state', + 'checked_data' => [0,1], + 'error_msg' => '状态有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 数据更新 + if(Db::name('GoodsSpecTemplate')->where(['id'=>intval($params['id'])])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()])) + { + return DataReturn(MyLang('common.operate_success'), 0); + } + return DataReturn(MyLang('common.operate_fail'), -100); + } +} +?> \ No newline at end of file diff --git a/app/service/NavigationService.php b/app/service/NavigationService.php index 9a0d250bc..bfb5f6656 100755 --- a/app/service/NavigationService.php +++ b/app/service/NavigationService.php @@ -12,7 +12,7 @@ namespace app\service; use think\facade\Db; use app\service\SystemService; -use app\service\BuyService; +use app\service\GoodsCartService; use app\service\MessageService; use app\service\OrderService; use app\service\GoodsService; @@ -648,7 +648,7 @@ class NavigationService if(!empty($params['user'])) { // 购物车商品总数 - $common_cart_total = BuyService::UserCartTotal(['user'=>$params['user']]); + $common_cart_total = GoodsCartService::UserGoodsCartTotal(['user'=>$params['user']]); // 未读消息总数 $message_params = ['user'=>$params['user'], 'is_more'=>1, 'is_read'=>0, 'user_type'=>'user']; @@ -1002,7 +1002,7 @@ class NavigationService if(!empty($params['user'])) { // 购物车商品总数 - $common_cart_total = BuyService::UserCartTotal(['user'=>$params['user']]); + $common_cart_total = GoodsCartService::UserGoodsCartTotal(['user'=>$params['user']]); } // 列表 diff --git a/app/service/ResourcesService.php b/app/service/ResourcesService.php index e39db5b16..6a1d1014e 100755 --- a/app/service/ResourcesService.php +++ b/app/service/ResourcesService.php @@ -584,7 +584,7 @@ class ResourcesService '', '

0) + { + var html = ''; + for(var i in result.data) + { + html += ''; + } + $spec_quick.find('select').append(html); + } else { + $spec_quick.find('select option').each(function(k, v) + { + if(k > 0) + { + $(this).remove(); + } + }); + } + $spec_quick.find('select').trigger('chosen:updated'); + }, + error: function(xhr, type) + { + Prompt(HtmlToString(xhr.responseText) || (window['lang_error_text'] || '异常错误')); + } + }); + }); + // 规格模板选择 + $(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) + { + 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) + { + 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 diff --git a/public/static/admin/default/js/index.js b/public/static/admin/default/js/index.js index 7ea46d2c9..aa62d8b46 100755 --- a/public/static/admin/default/js/index.js +++ b/public/static/admin/default/js/index.js @@ -1,13 +1,20 @@ $(function() { - /** - * url加载 - */ + // 左侧菜单箭头方向回调处理 + $('#admin-offcanvas li.admin-parent').on('open.collapse.amui', function() + { + $(this).find('a i').toggleClass('left-menu-more-ico-rotate'); + }).on('close.collapse.amui', function() + { + $(this).find('a i').toggleClass('left-menu-more-ico-rotate'); + }); + + // url加载 $(document).on('click', '.common-left-menu li a, .common-nav-top li a, .menu-mini-container-popup ul li a', function() { - var link = $(this).data('url'); + var link = $(this).data('url') || null; var type = $(this).data('type'); - if(link != undefined) + if(link != null) { // 打开url地址 $('#ifcontent').attr('src', link); @@ -28,30 +35,17 @@ $(function() { $('#admin-offcanvas').offCanvas('close'); } - } else { - // 左侧菜单剪头方向处理 - if(type == 'menu') - { - if($(this).find('i').length > 0) - { - $(this).find('i').toggleClass('left-menu-more-ico-rotate'); - } - } } }); - /** - * 菜单选择 - */ + // 菜单选择 $('.common-left-menu li a').on('click', function() { $('.common-left-menu a').removeClass('common-left-menu-active'); $(this).addClass('common-left-menu-active'); }); - /** - * mini伸缩开关 - */ + // mini伸缩开关 $('.menu-scaling-submit').on('click', function() { var status = $(this).attr('data-status') || 0; @@ -60,18 +54,18 @@ $(function() $('.menu-mini-container-tips').hide(); if(status == 0) { - $(this).animate({left: "59px"}, 300); + $(this).animate({left: '59px'}, 300); $(this).removeClass('am-icon-angle-double-left').addClass('am-icon-angle-double-right'); $('#admin-offcanvas').addClass('menu-mini').addClass('menu-mini-event'); - $('#admin-offcanvas').animate({width: "55px"}, 300); - $('#ifcontent').animate({paddingLeft: "55px"}, 300); - $('header.admin-header').animate({left: "54px"}, 300); + $('#admin-offcanvas').animate({width: '55px'}, 300); + $('#ifcontent').animate({paddingLeft: '55px'}, 300); + $('header.admin-header').animate({left: '54px'}, 300); } else { - $(this).animate({left: "164px"}, 300); + $(this).animate({left: '164px'}, 300); $(this).removeClass('am-icon-angle-double-right').addClass('am-icon-angle-double-left'); - $('#admin-offcanvas').animate({width: "160px"}, 300); - $('#ifcontent').animate({paddingLeft: "160px"}, 300); - $('header.admin-header').animate({left: "159px"}, 300); + $('#admin-offcanvas').animate({width: '160px'}, 300); + $('#ifcontent').animate({paddingLeft: '160px'}, 300); + $('header.admin-header').animate({left: '159px'}, 300); $('#admin-offcanvas').removeClass('menu-mini-event'); setTimeout(function() { $('#admin-offcanvas').removeClass('menu-mini'); @@ -81,9 +75,7 @@ $(function() $(this).attr('data-status', status == 0 ? 1 : 0); }); - /** - * mini菜单操作 - */ + // mini菜单操作 var timer_menu = null; $(document).on('mouseenter', '.menu-mini-event li', function() { @@ -91,29 +83,30 @@ $(function() var html = $(this).find('ul.admin-sidebar-sub').html() || null; var top = $(this).offset().top; var win_height = $(window).height(); + var $popup = $('.menu-mini-container-popup'); + var $tips = $('.menu-mini-container-tips'); if(html == null) { - $('.menu-mini-container-popup').hide(); - $('.menu-mini-container-tips').show(); - $('.menu-mini-container-tips').text($(this).find('.nav-name').text()); - $('.menu-mini-container-tips').css('top', top); + $popup.hide(); + $tips.show(); + $tips.text($(this).find('.nav-name').text()); + $tips.css('top', top); } else { - $('.menu-mini-container-popup ul').html(html); - $('.menu-mini-container-tips').hide(); - $('.menu-mini-container-popup').show(); + $popup.find('ul').html(html); + $tips.hide(); + $popup.show(); // 容器是否超出底部 - var h = $('.menu-mini-container-popup').height(); + var h = $popup.height(); if(h+top > win_height) { var t = win_height-h; - $('.menu-mini-container-popup').css('top', t); - $('.menu-mini-container-popup .mui-mbar-tab-tip').css('top', top-t+12); + $popup.css('top', t); + $popup.find('.mui-mbar-tab-tip').css('top', top-t+12); } else { - $('.menu-mini-container-popup').css('top', top); - $('.menu-mini-container-popup .mui-mbar-tab-tip').css('top', '10px'); + $popup.css('top', top); + $popup.find('.mui-mbar-tab-tip').css('top', '10px'); } - } }); $(document).on('mouseleave', '.menu-mini-event li', function() @@ -139,9 +132,7 @@ $(function() $(this).hide(); }); - /** - * mini菜单选择 - */ + // mini菜单选择 $(document).on('click', '.menu-mini-container-popup ul li a', function() { $('.admin-sidebar-list li a').removeClass('common-left-menu-active'); @@ -162,18 +153,18 @@ $(function() if($(document).width() <= 640) { $('.menu-scaling-submit').attr('data-status', 0); - $('.menu-scaling-submit').css({"left": "164px"}); + $('.menu-scaling-submit').css({'left': '164px'}); $('.menu-scaling-submit').removeClass('am-icon-angle-double-right').addClass('am-icon-angle-double-left'); - $('#admin-offcanvas').css({"width": "inherit"}); + $('#admin-offcanvas').css({'width': 'inherit'}); $('#admin-offcanvas').removeClass('menu-mini').removeClass('menu-mini-event'); - $('#ifcontent').css({"padding-left":0}); - $('header.admin-header').css({"left": 0}); + $('#ifcontent').css({'padding-left':0}); + $('header.admin-header').css({'left': 0}); } else { if(($('.menu-scaling-submit').attr('data-status') || 0) == 0) { - $('#admin-offcanvas').css({"width": "160px"}); - $('#ifcontent').css({"padding-left":"160px"}); - $('header.admin-header').css({"left": "159px"}); + $('#admin-offcanvas').css({'width': '160px'}); + $('#ifcontent').css({'padding-left':'160px'}); + $('header.admin-header').css({'left': '159px'}); } } }); diff --git a/public/static/common/css/common.css b/public/static/common/css/common.css index 980c7191d..672b45e2e 100755 --- a/public/static/common/css/common.css +++ b/public/static/common/css/common.css @@ -104,11 +104,13 @@ form.am-form .am-form-group-refreshing, .plug-file-upload-view { border-bottom: 0 !important; } -form.am-form-full-screen .am-form-group, -form.am-form-full-screen .plug-file-upload-view, -form.am-form-full-screen .business-form-group, -form.am-form-full-screen .business-form-block { - padding-right: 5px !important; +@media only screen and (min-width: 641px) { + form.am-form-full-screen .am-form-group, + form.am-form-full-screen .plug-file-upload-view, + form.am-form-full-screen .business-form-group, + form.am-form-full-screen .business-form-block { + padding-right: 5px !important; + } } /**