mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2024-11-30 19:08:59 +08:00
会员等级
This commit is contained in:
parent
4daba5fd90
commit
e323d0fb8a
@ -116,7 +116,7 @@ class Hook
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 免运费商品
|
// 免运费商品
|
||||||
$free_goods = $this->FreeShippingGoods($ret['data']['goods_ids'], $params);
|
$free_goods = $this->FreeShippingGoods(empty($ret['data']['goods_ids']) ? '' : $ret['data']['goods_ids'], $params);
|
||||||
$params['data']['base']['buy_count'] -= $free_goods['buy_count'];
|
$params['data']['base']['buy_count'] -= $free_goods['buy_count'];
|
||||||
$params['data']['base']['spec_weight_total'] -= $free_goods['spec_weight'];
|
$params['data']['base']['spec_weight_total'] -= $free_goods['spec_weight'];
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ namespace app\plugins\membershiplevel;
|
|||||||
|
|
||||||
use think\Controller;
|
use think\Controller;
|
||||||
use app\plugins\membershiplevel\Service;
|
use app\plugins\membershiplevel\Service;
|
||||||
use app\service\PluginsService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员等级插件 - 钩子入口
|
* 会员等级插件 - 钩子入口
|
||||||
@ -33,106 +32,97 @@ class Hook extends Controller
|
|||||||
*/
|
*/
|
||||||
public function run($params = [])
|
public function run($params = [])
|
||||||
{
|
{
|
||||||
|
// 后端访问不处理
|
||||||
|
if(isset($params['params']['is_admin_access']) && $params['params']['is_admin_access'] == 1)
|
||||||
|
{
|
||||||
|
return DataReturn('无需处理', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 钩子名称
|
||||||
if(!empty($params['hook_name']))
|
if(!empty($params['hook_name']))
|
||||||
{
|
{
|
||||||
|
// 当前模块/控制器/方法
|
||||||
|
$module_name = strtolower(request()->module());
|
||||||
|
$controller_name = strtolower(request()->controller());
|
||||||
|
$action_name = strtolower(request()->action());
|
||||||
|
|
||||||
|
// 页面参数
|
||||||
|
$input = input();
|
||||||
|
|
||||||
|
$ret = '';
|
||||||
switch($params['hook_name'])
|
switch($params['hook_name'])
|
||||||
{
|
{
|
||||||
// style css
|
case 'plugins_css' :
|
||||||
case 'plugins_common_header' :
|
$ret = __MY_ROOT_PUBLIC__.'static/plugins/css/membershiplevel/style.css';
|
||||||
$ret = $this->StyleCss($params);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 楼层数据上面
|
// 商品数据处理后
|
||||||
case 'plugins_view_home_floor_top' :
|
case 'plugins_service_goods_handle_end' :
|
||||||
$ret = $this->HomeFloorTopAdv($params);
|
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;
|
break;
|
||||||
default :
|
|
||||||
$ret = '';
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 首页楼层顶部广告
|
* 商品处理结束钩子
|
||||||
* @author Devil
|
* @author Devil
|
||||||
* @blog http://gong.gg/
|
* @blog http://gong.gg/
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @datetime 2019-02-06T16:16:34+0800
|
* @date 2019-03-26
|
||||||
* @param [array] $params [输入参数]
|
* @desc description
|
||||||
|
* @param [array] &$goods [商品数据]
|
||||||
*/
|
*/
|
||||||
public function HomeFloorTopAdv($params = [])
|
private function GoodsHandleEnd(&$goods = [])
|
||||||
{
|
{
|
||||||
// 获取应用数据
|
// 用户等级
|
||||||
$ret = PluginsService::PluginsData('membershiplevel');
|
$level = Service::UserLevelMatching();
|
||||||
if($ret['code'] == 0)
|
if(!empty($level) && $level['discount_rate'] > 0)
|
||||||
{
|
{
|
||||||
// 有效时间
|
if(empty($goods['original_price']))
|
||||||
if(!empty($ret['data']['time_start']))
|
|
||||||
{
|
{
|
||||||
// 是否已开始
|
$goods['original_price'] = $goods['price'];
|
||||||
if(strtotime($ret['data']['time_start']) > time())
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!empty($ret['data']['time_end']))
|
|
||||||
{
|
|
||||||
// 是否已结束
|
|
||||||
if(strtotime($ret['data']['time_end']) < time())
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取图片列表
|
// 价格处理
|
||||||
$ret = Service::DataList();
|
$goods['price'] = Service::PriceCalculate($goods['price'], $level['discount_rate'], 0);
|
||||||
if($ret['code'] == 0 && !empty($ret['data']))
|
$price_title = empty($level['name']) ? '会员价' : $level['name'];
|
||||||
{
|
$goods['show_field_price_text'] = '<span class="plugins-membershiplevel-goods-price-icon">'.$price_title.'</span>';
|
||||||
$this->assign('data_list', $ret['data']);
|
|
||||||
return $this->fetch('../../../plugins/view/membershiplevel/index/content');
|
|
||||||
}
|
}
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* css
|
* 商品规格基础数据
|
||||||
* @author Devil
|
* @author Devil
|
||||||
* @blog http://gong.gg/
|
* @blog http://gong.gg/
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @datetime 2019-02-06T16:16:34+0800
|
* @date 2019-03-26
|
||||||
* @param [array] $params [输入参数]
|
* @desc description
|
||||||
|
* @param [array] &$spec_base [规格信息]
|
||||||
*/
|
*/
|
||||||
public function StyleCss($params = [])
|
private function GoodsSpecBase(&$spec_base = [])
|
||||||
{
|
{
|
||||||
return '<style type="text/css">
|
// 用户等级
|
||||||
@media only screen and (min-width:640px) {
|
$level = Service::UserLevelMatching();
|
||||||
.plugins-membershiplevel-home-adv ul.am-gallery img {
|
if(!empty($level) && $level['discount_rate'] > 0 && isset($spec_base['price']))
|
||||||
-webkit-transition: transform .2s ease-in;
|
{
|
||||||
-moz-transition: transform .2s ease-in;
|
if(empty($spec_base['original_price']))
|
||||||
-ms-transition: transform .2s ease-in;
|
{
|
||||||
-o-transition: transform .2s ease-in;
|
$spec_base['original_price'] = $spec_base['price'];
|
||||||
transition: transform .2s ease-in;
|
}
|
||||||
}
|
$spec_base['price'] = Service::PriceCalculate($spec_base['price'], $level['discount_rate'], 0);
|
||||||
.plugins-membershiplevel-home-adv ul.am-gallery img:hover {
|
}
|
||||||
-ms-transform: translate3d(0px, -3px, 0px);
|
|
||||||
-webkit-transform: translate3d(0px, -3px, 0px);
|
|
||||||
-o-transform: translate3d(0px, -3px, 0px);
|
|
||||||
transform: translate3d(0px, -3px, 0px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media only screen and (min-width:1025px) {
|
|
||||||
.plugins-membershiplevel-home-adv {
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
.plugins-membershiplevel-home-adv ul.am-gallery {
|
|
||||||
width: calc(100% + 20px);
|
|
||||||
margin-left: -10px;
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -10,8 +10,10 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\plugins\membershiplevel;
|
namespace app\plugins\membershiplevel;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
use app\service\PluginsService;
|
use app\service\PluginsService;
|
||||||
use app\service\ResourcesService;
|
use app\service\ResourcesService;
|
||||||
|
use app\service\UserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员等级服务层
|
* 会员等级服务层
|
||||||
@ -50,6 +52,22 @@ class Service
|
|||||||
// 获取数据
|
// 获取数据
|
||||||
$ret = PluginsService::PluginsData('membershiplevel', self::$base_config_attachment_field);
|
$ret = PluginsService::PluginsData('membershiplevel', self::$base_config_attachment_field);
|
||||||
$data = (empty($ret['data']) || empty($ret['data'][$data_field])) ? [] : $ret['data'][$data_field];
|
$data = (empty($ret['data']) || empty($ret['data'][$data_field])) ? [] : $ret['data'][$data_field];
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
return self::LevelDataHandle($data, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户等级数据列表处理
|
||||||
|
* @author Devil
|
||||||
|
* @blog http://gong.gg/
|
||||||
|
* @version 1.0.0
|
||||||
|
* @datetime 2019-04-27T01:08:23+0800
|
||||||
|
* @param [array] $data [等级数据]
|
||||||
|
* @param [array] $params [输入参数]
|
||||||
|
*/
|
||||||
|
public static function LevelDataHandle($data, $params = [])
|
||||||
|
{
|
||||||
if(!empty($data))
|
if(!empty($data))
|
||||||
{
|
{
|
||||||
$common_is_enable_tips = lang('common_is_enable_tips');
|
$common_is_enable_tips = lang('common_is_enable_tips');
|
||||||
@ -183,8 +201,8 @@ class Service
|
|||||||
// 数据
|
// 数据
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'rules_min' => intval($params['rules_min']),
|
'rules_min' => $params['rules_min'],
|
||||||
'rules_max' => intval($params['rules_max']),
|
'rules_max' => $params['rules_max'],
|
||||||
'images_url' => $attachment['data']['images_url'],
|
'images_url' => $attachment['data']['images_url'],
|
||||||
'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0,
|
'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0,
|
||||||
'discount_rate' => isset($params['discount_rate']) ? $params['discount_rate'] : 0,
|
'discount_rate' => isset($params['discount_rate']) ? $params['discount_rate'] : 0,
|
||||||
@ -299,5 +317,133 @@ class Service
|
|||||||
// 保存
|
// 保存
|
||||||
return PluginsService::PluginsDataSave(['plugins'=>'membershiplevel', 'data'=>$ret['data']]);
|
return PluginsService::PluginsDataSave(['plugins'=>'membershiplevel', 'data'=>$ret['data']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠价格计算
|
||||||
|
* @author Devil
|
||||||
|
* @blog http://gong.gg/
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2019-03-26
|
||||||
|
* @desc description
|
||||||
|
* @param [string] $price [商品展示金额]
|
||||||
|
* @param [int] $plugins_discount [折扣系数]
|
||||||
|
* @param [int] $plugins_price [减金额]
|
||||||
|
*/
|
||||||
|
public static function PriceCalculate($price, $plugins_discount = 0, $plugins_price = 0)
|
||||||
|
{
|
||||||
|
if($plugins_discount <= 0 && $plugins_price <= 0)
|
||||||
|
{
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 折扣
|
||||||
|
if($plugins_discount > 0)
|
||||||
|
{
|
||||||
|
if(stripos($price, '-') !== false)
|
||||||
|
{
|
||||||
|
$text = explode('-', $price);
|
||||||
|
$min_price = $text[0]*$plugins_discount;
|
||||||
|
$max_price = $text[1]*$plugins_discount;
|
||||||
|
$price = ($min_price <= 0) ? '0.00' : PriceNumberFormat($min_price);
|
||||||
|
$price .= '-'.(($max_price <= 0) ? '0.00' : PriceNumberFormat($max_price));
|
||||||
|
} else {
|
||||||
|
$price = (float) $price *$plugins_discount;
|
||||||
|
$price = ($price <= 0) ? '0.00' : PriceNumberFormat($price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 减金额
|
||||||
|
if($plugins_price > 0)
|
||||||
|
{
|
||||||
|
if(stripos($price, '-') !== false)
|
||||||
|
{
|
||||||
|
$text = explode('-', $price);
|
||||||
|
$min_price = $text[0]-$plugins_price;
|
||||||
|
$max_price = $text[1]-$plugins_price;
|
||||||
|
$price = ($min_price <= 0) ? '0.00' : PriceNumberFormat($min_price);
|
||||||
|
$price .= '-'.(($max_price <= 0) ? '0.00' : PriceNumberFormat($max_price));
|
||||||
|
} else {
|
||||||
|
$price = (float) $price-$plugins_price;
|
||||||
|
$price = ($price <= 0) ? '0.00' : PriceNumberFormat($price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户等级匹配
|
||||||
|
* @author Devil
|
||||||
|
* @blog http://gong.gg/
|
||||||
|
* @version 1.0.0
|
||||||
|
* @datetime 2019-04-27T00:32:00+0800
|
||||||
|
*/
|
||||||
|
public static function UserLevelMatching()
|
||||||
|
{
|
||||||
|
// 用户
|
||||||
|
$user = UserService::LoginUserInfo();
|
||||||
|
if(!empty($user))
|
||||||
|
{
|
||||||
|
// 缓存key
|
||||||
|
$key = 'plugins_membershiplevel_cache_user_level_'.$user['id'];
|
||||||
|
$level = cache($key);
|
||||||
|
|
||||||
|
// 应用配置
|
||||||
|
if(empty($level) || config('app_debug') == true)
|
||||||
|
{
|
||||||
|
$base = PluginsService::PluginsData('membershiplevel', Service::$base_config_attachment_field);
|
||||||
|
if(!empty($base['data']['level_list']))
|
||||||
|
{
|
||||||
|
// 匹配类型
|
||||||
|
$value = 0;
|
||||||
|
switch($base['data']['level_rules'])
|
||||||
|
{
|
||||||
|
// 积分(可用积分)
|
||||||
|
case 0 :
|
||||||
|
$value = isset($user['integral']) ? intval($user['integral']) : 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// 消费总额(已完成订单)
|
||||||
|
// 订单状态(0待确认, 1已确认/待支付, 2已支付/待发货, 3已发货/待收货, 4已完成, 5已取消, 6已关闭)
|
||||||
|
case 1 :
|
||||||
|
$where = ['user_id'=>$user['id'], 'status'=>4];
|
||||||
|
$value = (float) Db::name('Order')->where($where)->sum('total_price');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 匹配相应的等级
|
||||||
|
$level_list = self::LevelDataHandle($base['data']['level_list']);
|
||||||
|
foreach($level_list['data'] as $rules)
|
||||||
|
{
|
||||||
|
if(isset($rules['is_enable']) && $rules['is_enable'] == 1)
|
||||||
|
{
|
||||||
|
// 0-*
|
||||||
|
if($rules['rules_min'] <= 0 && $rules['rules_max'] > 0 && $value < $rules['rules_max'])
|
||||||
|
{
|
||||||
|
$level = $rules;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// *-*
|
||||||
|
if($rules['rules_min'] > 0 && $rules['rules_max'] > 0 && $value >= $rules['rules_min'] && $value < $rules['rules_max'])
|
||||||
|
{
|
||||||
|
$level = $rules;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// *-0
|
||||||
|
if($rules['rules_max'] <= 0 && $rules['rules_min'] > 0 && $value > $rules['rules_min'])
|
||||||
|
{
|
||||||
|
$level = $rules;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cache($key, $level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -21,10 +21,13 @@
|
|||||||
"is_home":false
|
"is_home":false
|
||||||
},
|
},
|
||||||
"hook":{
|
"hook":{
|
||||||
"plugins_common_header":[
|
"plugins_css":[
|
||||||
"app\\plugins\\membershiplevel\\Hook"
|
"app\\plugins\\membershiplevel\\Hook"
|
||||||
],
|
],
|
||||||
"plugins_view_home_floor_top":[
|
"plugins_service_goods_handle_end":[
|
||||||
|
"app\\plugins\\membershiplevel\\Hook"
|
||||||
|
],
|
||||||
|
"plugins_service_goods_spec_base":[
|
||||||
"app\\plugins\\membershiplevel\\Hook"
|
"app\\plugins\\membershiplevel\\Hook"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@
|
|||||||
<div class="am-form-group">
|
<div class="am-form-group">
|
||||||
<label>规则值</label>
|
<label>规则值</label>
|
||||||
<div class="rules-value">
|
<div class="rules-value">
|
||||||
<input type="number" placeholder="最小值" name="rules_min" data-validation-message="请填写规则最小值" class="am-radius" {{if isset($data['rules_min'])}} value="{{$data.rules_min}}"{{/if}} required />
|
<input type="number" placeholder="最小值" name="rules_min" step="0.01" data-validation-message="请填写规则最小值" class="am-radius" {{if isset($data['rules_min'])}} value="{{$data.rules_min}}"{{/if}} required />
|
||||||
<span>~</span>
|
<span>~</span>
|
||||||
<input type="number" placeholder="最大值" name="rules_max" data-validation-message="请填写规则最大值" class="am-radius" {{if isset($data['rules_max'])}} value="{{$data.rules_max}}"{{/if}} required />
|
<input type="number" placeholder="最大值" step="0.01" name="rules_max" data-validation-message="请填写规则最大值" class="am-radius" {{if isset($data['rules_max'])}} value="{{$data.rules_max}}"{{/if}} required />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ return array (
|
|||||||
0 => 'app\\plugins\\freightfee\\Hook',
|
0 => 'app\\plugins\\freightfee\\Hook',
|
||||||
1 => 'app\\plugins\\share\\Hook',
|
1 => 'app\\plugins\\share\\Hook',
|
||||||
2 => 'app\\plugins\\footercustomerservice\\Hook',
|
2 => 'app\\plugins\\footercustomerservice\\Hook',
|
||||||
|
3 => 'app\\plugins\\membershiplevel\\Hook',
|
||||||
),
|
),
|
||||||
'plugins_service_buy_handle' =>
|
'plugins_service_buy_handle' =>
|
||||||
array (
|
array (
|
||||||
@ -141,5 +142,13 @@ return array (
|
|||||||
array (
|
array (
|
||||||
0 => 'app\\plugins\\footercustomerservice\\Hook',
|
0 => 'app\\plugins\\footercustomerservice\\Hook',
|
||||||
),
|
),
|
||||||
|
'plugins_service_goods_handle_end' =>
|
||||||
|
array (
|
||||||
|
0 => 'app\\plugins\\membershiplevel\\Hook',
|
||||||
|
),
|
||||||
|
'plugins_service_goods_spec_base' =>
|
||||||
|
array (
|
||||||
|
0 => 'app\\plugins\\membershiplevel\\Hook',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
?>
|
?>
|
5
public/static/plugins/css/membershiplevel/style.css
Normal file
5
public/static/plugins/css/membershiplevel/style.css
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.plugins-membershiplevel-goods-price-icon {
|
||||||
|
padding: 3px 5px;
|
||||||
|
background: #ffc31e;
|
||||||
|
color: #fff;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user