文件
mashangyoujiu/Application/Common/Model/RetailVipConfigModel.class.php

311 行
13 KiB
PHP
可执行文件

<?php
namespace Common\Model;
use Think\Model;
//[1.8.93]
/**
* 会员设置表
* Class RetailVipConfigModel
* @package Common\Model
*/
class RetailVipConfigModel extends BaseModel
{
protected $tableName = 'vip_config';
const ID = 'id';
const MERCHANT_ID = 'merchantid';
const VIP_DETAIL = 'vip_detail';
const SIGN_IN_GIVE = 'signin_give';
const INFO_SCORE = 'infoscore';
const FLOWER_PRICE = 'flower_price'; //普通会员消费金额
const PERCENT = 'percent';
const PERCENT_STATE = 'percent_state';
const STYLE_MODEL = 'style_model';
const RECHARGE_STATE = 'recharge_state';
const RECHARGE_PRICE = 'recharge_price'; //普通会员充值金额
const RECHARGE_INTEGRAL = 'recharge_integral';
const VIP_TEMPLATE_SIGN = 'viptemplatesign';
const PLUS_SIGN_IN_GIVE = 'plus_signin_give';
const PLUS_INFO_SCORE = 'plus_infoscore';
const PLUS_FLOWER_TYPE = 'plus_flower_type'; //1消费是常规会员的倍数 2消费多少元获得多少积分
const PLUS_FLOWER_PRICE = 'plus_flower_price'; //plus会员消费金额
const PLUS_FLOWER_PERCENT = 'plus_flower_percent'; //plus会员消费多少元获得的积分
const PLUS_PERCENT = 'plus_percent';
const PLUS_PERCENT_STATE = 'plus_percent_state';
const PLUS_RECHARGE_INTEGRAL = 'plus_recharge_integral';
const PLUS_RECHARGE_STATE = 'plus_recharge_state';
const PLUS_RECHARGE_TYPE = 'plus_recharge_type'; //1充值普通会员金额获得几倍积分 2充值多少金额获得多少积分
const PLUS_RECHARGE_PRICE = 'plus_recharge_price'; //充值金额
const PLUS_RECHARGE_GET_INTEGRAL = 'plus_recharge_get_integral';//充值获得积分
const GOODS_INTEGRAL_STATE = 'goods_integral_state';
const GOODS_INTEGRAL_PLUS_STATE = 'goods_integral_plus_state';
const GOODS_INTEGRAL_MULTIPLE = 'goods_integral_multiple';
const ADD_TIME = 'addtime';
/**
* plus会员设置参数验证
* @param $data
* @return mixed
*/
public function verify_param($data)
{
$reg = "/^[0-9]+(.[0-9]{1,2})?$/";
$bg = "/^\+?[1-9][0-9]*$/";
if ($data['plus_percent_state'] == 1) {
if ($data['plus_flower_type'] == 2) {
if (empty($data['plus_flower_price']) || empty($data['plus_flower_percent'])) {
$res = array('status' => 0, 'msg' => '请输入消费金额或积分');
return $res;
}
if (!preg_match($reg, $data['plus_flower_price'])) {
$res = array('status' => 0, 'msg' => '请输入正确的消费金额');
return $res;
}
if (!preg_match($bg, $data['plus_flower_percent'])) {
$res = array('status' => 0, 'msg' => '请输入正确的消费获得的积分');
return $res;
}
} else {
if (empty($data['plus_percent']) || !preg_match($reg, $data['plus_percent'])) {
$res = array('status' => 0, 'msg' => '请输入正确的消费获得的积分倍数');
return $res;
}
}
}
if ($data['plus_recharge_state'] == 1) {
if ($data['plus_recharge_type'] == 2) {
//plus会员开启充多少获得多少积分
if (empty($data['plus_recharge_price']) || empty($data['plus_recharge_get_integral'])) {
$res = array('status' => 0, 'msg' => '请输入消费金额或积分');
return $res;
}
if (!preg_match($reg, $data['plus_recharge_price'])) {
$res = array('status' => 0, 'msg' => '请输入正确的充值金额');
return $res;
}
if (!preg_match($bg, $data['plus_recharge_get_integral'])) {
$res = array('status' => 0, 'msg' => '请输入正确的充值获得的积分');
return $res;
}
} else {
if (empty($data['plus_recharge_integral']) || !preg_match($reg, $data['plus_recharge_integral'])) {
$res = array('status' => 0, 'msg' => '请输入正确的充值获得的积分倍数');
return $res;
}
}
}
$res = array('status' => 1, 'msg' => '验证成功');
return $res;
}
/**
* plus会员积分设置
* @param $data
* @return mixed
*/
public function addPlusData($data)
{
//plus会员积分验证
$signin_give = $data['plus_signin_give'];
$infoscore = $data['plus_infoscore'];
$preg_match = "/^[0-9]*$/";
if($signin_give !== '' && !preg_match($preg_match,$signin_give)){
$res['status'] = 0;
$res['msg'] = '请输入正确的赠送积分';
return $res;
}
if($infoscore !== '' && !preg_match($preg_match,$infoscore)){
$res['status'] = 0;
$res['msg'] = '请输入正确的赠送积分';
return $res;
}
$content = array(
'plus_signin_give' => $data['plus_signin_give'],
'plus_infoscore' => $data['plus_infoscore'],
'plus_percent_state' => $data['plus_percent_state'],
'plus_pay_integral_state' => $data['plus_pay_integral_state'],
'plus_recharge_state' => $data['plus_recharge_state'],
'goods_integral_plus_state' => $data['goods_integral_plus_state'],
'goods_integral_multiple' => $data['goods_integral_multiple'],
'plus_flower_type' => $data['plus_flower_type'] ? $data['plus_flower_type'] : 1,
'plus_recharge_type' => $data['plus_recharge_type'] ? $data['plus_recharge_type'] : 1,
);
if ($data['plus_percent_state'] == 1) {
//开启消费送积分
if ($data['plus_flower_type'] == 2) {
$content['plus_flower_price'] = $data['plus_flower_price'] ? $data['plus_flower_price'] : null;
$content['plus_flower_percent'] = $data['plus_flower_percent'] ? $data['plus_flower_percent'] : null;
} else {
$content['plus_percent'] = $data['plus_percent'];
}
}
if ($data['plus_recharge_state'] == 1) {
//开启充值送积分
if ($data['plus_recharge_type'] == 2) {
$content['plus_recharge_price'] = $data['plus_recharge_price'] ? $data['plus_recharge_price'] : null;
$content['plus_recharge_get_integral'] = $data['plus_recharge_get_integral'] ? $data['plus_recharge_get_integral'] : null;
} else {
$content['plus_recharge_integral'] = $data['plus_recharge_integral'];
}
}
if (!empty($data['id'])) {
$state = $this->updateOrder(array('id' => $data['id']), $content);
} else {
$content['merchantid'] = $data['merchantid'];
$state = $this->addOrder($content);
}
if ($state) {
$res = array('status' => 1, 'msg' => '操作成功');
} else {
$res = array('status' => 1, 'msg' => '暂无修改');
}
return $res;
}
/**
* 基于订单消费送积分验证用户身份是否开启送积分
* @param $parameter
* @return bool
*/
public function buy_integral_config($parameter)
{
$vip_type = $parameter['vip_type'];
$vipConfig = $parameter['vip_config'];
$percent_state = false;
if ($vip_type == 2 && $vipConfig['plus_percent_state'] == 1) {
//商户开启plus会员买单送积分
switch ($vipConfig['plus_flower_type']) {
case 1:
//1消费是常规会员的倍数
if ($vipConfig['plus_percent'] > 0 && $vipConfig['flower_price'] > 0 && $vipConfig['percent'] > 0) {
$percent_state = true;
}
break;
case 2:
if ($vipConfig['plus_flower_price'] > 0 && $vipConfig['plus_flower_percent'] > 0) {
$percent_state = true;
}
break;
}
} else {
//商户开启普通会员买单送积分
if ($vipConfig['percent_state'] == 1 && $vipConfig['flower_price'] > 0 && $vipConfig['percent'] > 0) {
$percent_state = true;
}
}
return $percent_state;
}
/**
* 基于订单消费送积分
* @param $parameter [vip_type 2plus会员]
* @return mixed
*/
public function buy_get_integral($parameter)
{
$vip_type = $parameter['vip_type'];
$vip_config = $parameter['vip_config'];
$all_money = $parameter['all_money'];
$get_integral = 0;
if ($vip_type == 2 && $vip_config['plus_percent_state'] == 1) {
//plus会员消费多少元获得多少积分
switch ($vip_config['plus_flower_type']) {
case 1:
$get_integral = floor($all_money / $vip_config['flower_price'] * $vip_config['percent'] * $vip_config['plus_percent']);
break;
case 2:
$get_integral = floor($all_money / $vip_config['plus_flower_price'] * $vip_config['plus_flower_percent']);
break;
}
} else {
$get_integral = floor($all_money / $vip_config['flower_price'] * $vip_config['percent']);
}
return $get_integral;
}
/**
* 基于商品送积分
* @param $parameter[vip_type=>[2plus会员],vip_config=>设置,integral=>积分,num=>数量]
* @return float|int
*/
public function buy_goods_get_integral($parameter)
{
$vip_type = $parameter['vip_type'];
$vip_config = $parameter['vip_config'];
$integral = $parameter['integral'];
$num = $parameter['num'];
$get_integral = 0;
if ($vip_type == 2 && $vip_config['goods_integral_plus_state'] == 1 && $vip_config['goods_integral_multiple'] > 0) {
$get_integral = round($integral * $num * $vip_config['goods_integral_multiple']); //Plus会员开启
} else if ($vip_config['goods_integral_state'] == 1) {
$get_integral = round($integral * $num);
}
return $get_integral;
}
/**
* 充值送积分验证用户身份是否开启送积分
* @param $parameter [vip_type=>[3plus会员其他普通会员]]
* @return bool
*/
public function recharge_integral_config($parameter)
{
$vip_type = $parameter['vip_type'];
$vip_config = $parameter['vip_config'];
$percent_state = false;
if ($vip_type == 3 && $vip_config['plus_recharge_state'] == 1) {
//商户开启plus会员买单送积分
switch ($vip_config['plus_recharge_type']) {
case 1:
//1充值是常规会员的倍数
if ($vip_config['recharge_price'] > 0 && $vip_config['recharge_integral'] > 0 && $vip_config['plus_recharge_integral'] > 0) {
$percent_state = true;
}
break;
case 2:
if ($vip_config['plus_recharge_price'] > 0 && $vip_config['plus_recharge_get_integral'] > 0) {
$percent_state = true;
}
break;
}
} else {
//商户开启普通会员充值送积分
if ($vip_config['recharge_state'] == 1 && $vip_config['recharge_price'] > 0 && $vip_config['recharge_integral'] > 0) {
$percent_state = true;
}
}
return $percent_state;
}
/**
* 充值获取积分
* @param $parameter
* @return bool
*/
public function recharge_get_integral($parameter)
{
$vip_info = $parameter['vip_info'];
$vip_config = $parameter['vip_config'];
$vip_type = $parameter['vip_type'];
$recharge_order = $parameter['recharge_order'];
$integral = 0;
if ($vip_type == 3 && $vip_config['plus_recharge_state'] == 1) {
switch ($vip_config['plus_recharge_type']) {
case 1:
$integral = floor($recharge_order['money'] / $vip_config['recharge_price'] * $vip_config['recharge_integral'] * $vip_config['plus_recharge_integral']);
break;
case 2:
$integral = floor($recharge_order['money'] / $vip_config['plus_recharge_price'] * $vip_config['plus_recharge_get_integral']);
break;
}
} else {
$integral = floor($recharge_order['money'] / $vip_config['recharge_price'] * $vip_config['recharge_integral']);
}
return $integral;
}
}