module()); $controller_name = strtolower(request()->controller()); $action_name = strtolower(request()->action()); // 页面参数 $input = input(); $ret = ''; switch($params['hook_name']) { case 'plugins_css' : $ret = __MY_ROOT_PUBLIC__.'static/plugins/css/membershiplevel/style.css'; break; // 商品数据处理后 case 'plugins_service_goods_handle_end' : if(!empty($params['goods']['id']) && !empty($input['id']) && $params['goods']['id'] == $input['id'] && $module_name.$controller_name.$action_name == 'indexgoodsindex') { $this->GoodsHandleEnd($params['goods']); } break; // 商品规格基础数据 case 'plugins_service_goods_spec_base' : $this->GoodsSpecBase($params['spec_base']); break; // 满减优惠 case 'plugins_service_buy_handle' : $ret = $this->FullReductionCalculate($params); break; } return $ret; } else { return ''; } } /** * 满减计算 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2019-03-21 * @desc description * @param [array] $params [输入参数] */ public function FullReductionCalculate($params = []) { // 用户等级 $level = Service::UserLevelMatching(); if(!empty($level) && $level['order_price'] > 0 && $level['full_reduction_price'] > 0 && $params['data']['base']['total_price'] >= $level['order_price']) { // 扩展展示数据 $show_name = $level['name'].'-满减'; $params['data']['extension_data'][] = [ 'name' => $show_name, 'price' => $level['full_reduction_price'], 'type' => 1, 'tips' => '-¥'.$level['full_reduction_price'].'元', ]; // 金额 $params['data']['base']['preferential_price'] += $level['full_reduction_price']; $params['data']['base']['actual_price'] -= $level['full_reduction_price']; return DataReturn('处理成功', 0); } return DataReturn('无需处理', 0); } /** * 商品处理结束钩子 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2019-03-26 * @desc description * @param [array] &$goods [商品数据] */ private function GoodsHandleEnd(&$goods = []) { // 用户等级 $level = Service::UserLevelMatching(); if(!empty($level) && $level['discount_rate'] > 0) { if(empty($goods['original_price'])) { $goods['original_price'] = $goods['price']; } // 价格处理 $goods['price'] = Service::PriceCalculate($goods['price'], $level['discount_rate'], 0); $price_title = empty($level['name']) ? '会员价' : $level['name']; $goods['show_field_price_text'] = ''.$price_title.''; } } /** * 商品规格基础数据 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2019-03-26 * @desc description * @param [array] &$spec_base [规格信息] */ private function GoodsSpecBase(&$spec_base = []) { // 用户等级 $level = Service::UserLevelMatching(); if(!empty($level) && $level['discount_rate'] > 0 && isset($spec_base['price'])) { if(empty($spec_base['original_price'])) { $spec_base['original_price'] = $spec_base['price']; } $spec_base['price'] = Service::PriceCalculate($spec_base['price'], $level['discount_rate'], 0); } } } ?>