249 行
12 KiB
PHP
可执行文件
249 行
12 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace CashierApi\Controller;
|
|
|
|
use Common\Business\ShopCoupon;
|
|
use Common\Model\RetailBillOrderModel;
|
|
use Common\Model\RetailGoodsModel;
|
|
use Common\Model\RetailMerchantConfigModel;
|
|
use Common\Model\RetailSellModel;
|
|
use Common\Model\RetailSkuGoodsModel;
|
|
use Common\Model\RetailVipIntegralModel;
|
|
use Common\Model\RetailVipModel;
|
|
//[1.7.14]
|
|
class ShopCouponController extends BaseController
|
|
{
|
|
/**
|
|
* 获取商家券信息
|
|
*/
|
|
public function basisCodeGetShopCouponInfo()
|
|
{
|
|
$data = I("post.");
|
|
$shop_coupon_code = $data['shop_coupon_code']; //券码
|
|
$order_money = $data['all_money']; //前台计算的总金额
|
|
$order_no = $data['order_no']; //订单号
|
|
$vid = $data['vid']; //会员id
|
|
$discount = $data['discount'] ? $data['discount'] : 1; //收银员手动打折折扣值
|
|
$integral_cashing = $data['integral_cashing']; //是否使用积分抵扣 1是 0否
|
|
$cashier_preferential_state = self::$cashier['preferential']; //收银员打折权限
|
|
$cashier_manual_discount_state = self::$cashier['manual_discount']; // 收银员-单品折扣权限
|
|
$manual_min_discount_state = self::$cashier['manual_min_discount']; // 收银员-手动折扣最低折扣
|
|
$manual_max_amount_state = self::$cashier['manual_max_amount']; // 收银员-手动折扣最多优惠金额
|
|
$store_preferential_state = self::$store['preferential']; //门店打折权限
|
|
$store_manual_discount_state = self::$store['manual_discount']; // 门店折上折--收银员
|
|
$ShopCouponClass = new ShopCoupon();
|
|
$result = $ShopCouponClass->getCouponInfo([
|
|
'coupon_code' => $shop_coupon_code,
|
|
'merchant_id' => self::$merchant_id,
|
|
'verification_available_type' => 2,
|
|
'verification_store_id' => self::$store_id
|
|
]);
|
|
if ($result['status'] != 1) {
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$shop_coupon = $result['data']['shop_coupon']; //商家券信息
|
|
$BillModel = new RetailBillOrderModel();
|
|
$map = array(
|
|
$BillModel::ORDER_NO => strval($order_no),
|
|
$BillModel::STORE_ID => self::$store_id,
|
|
$BillModel::PAY_STATE => array('in', '0,2'), //未支付或待支付状态
|
|
$BillModel::REFUND_MONEY => 0,
|
|
);
|
|
$billOrder = $BillModel->getFind($map, "id"); //订单信息
|
|
if (empty($billOrder)) {
|
|
$result['status'] = 0;
|
|
$result['message'] = '订单不存在';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
if (!empty($discount)) {
|
|
if (!verifyNumber($discount, 3, 0.001, 1)) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '折扣值取值有误';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
if ($discount < 1) {
|
|
if ($cashier_preferential_state != 1) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '您没有打折的权限';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
}
|
|
$MerchantConfigModel = new RetailMerchantConfigModel();
|
|
$v_discount = 1; //会员等级折扣
|
|
//查找会员等级
|
|
if (!empty($vid)) {
|
|
$VipModel = new RetailVipModel();
|
|
$map = array(
|
|
$VipModel::MERCHANT_ID => self::$merchant_id,
|
|
$VipModel::STATUS => 1,
|
|
$VipModel::ID => $vid
|
|
);
|
|
$fields = array(
|
|
$VipModel::ID,
|
|
$VipModel::GRADE_INTEGRAL,
|
|
$VipModel::INTEGRAL,
|
|
$VipModel::PLUS_TYPE
|
|
);
|
|
$vip = $VipModel->getFind($map, $fields);
|
|
if (empty($vip)) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '会员信息有误';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
//查找会员等级
|
|
if ($store_preferential_state == 1 || ($discount == 1 && $store_preferential_state != 1)) {
|
|
//门店开启折上折
|
|
$VipIntegralModel = new RetailVipIntegralModel();
|
|
$map = array(
|
|
$VipIntegralModel::MERCHANT_ID => self::$merchant_id,
|
|
$VipIntegralModel::DISCOUNT => array('gt', 0)
|
|
);
|
|
if ($vip[$VipModel::PLUS_TYPE] == 2) {
|
|
//plus会员
|
|
$grade = $VipIntegralModel->getOrderFind($map, '*', $VipIntegralModel::DISCOUNT . ' asc');
|
|
} else {
|
|
//常规会员
|
|
$map[$VipIntegralModel::MIN_INTEGRAL] = array('ELT', $vip[$VipModel::GRADE_INTEGRAL]);
|
|
$grade = $VipIntegralModel->getOrderFind($map, '*', $VipIntegralModel::MIN_INTEGRAL . ' desc');
|
|
}
|
|
if (!empty($grade)) {
|
|
$v_discount = $grade[$VipIntegralModel::DISCOUNT];
|
|
}
|
|
if (!verifyNumber($v_discount, 3, 0.001, 1)) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '会员等级折扣值有误';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
}
|
|
$SellModel = new RetailSellModel();
|
|
$map = array(
|
|
's.' . $SellModel::BILL_ID => $billOrder['id']
|
|
);
|
|
$GoodsModel = new RetailGoodsModel();
|
|
$fields = array(
|
|
's.*',
|
|
's.' . $SellModel::ORIGINAL_PRICE . ' as before_price',
|
|
's.' . $SellModel::CASHIER_MANUAL_DIS,
|
|
'g.' . $GoodsModel::STORE_MEM_STATUS,
|
|
'g.' . $GoodsModel::STORE_MEM_PRICE,
|
|
'g.' . $GoodsModel::VIP_RETAIL_STATE,
|
|
'g.' . $GoodsModel::PLUS_PRICE,
|
|
'g.' . $GoodsModel::PLUS_MEM_STATUS,
|
|
'g.' . $GoodsModel::GUIDE_ROYALTY_STATE,
|
|
'g.' . $GoodsModel::GUIDE_ROYALTY_CUSTOM_STATE,
|
|
'g.' . $GoodsModel::GUIDE_ROYALTY_PRICE,
|
|
'g.' . $GoodsModel::ATTRIBUTE_STATE,
|
|
'g.store_mem_integral',
|
|
'g.plus_mem_integral'
|
|
);
|
|
//获取sell详情
|
|
$sellOrder = $SellModel->getSelectAndGoods($map, $fields, 's.' . $SellModel::ORIGINAL_PRICE . ' asc');
|
|
if (empty($sellOrder)) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '订单信息异常';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
//会员打折或者把价格改为会员价-- 手动打折
|
|
$SkuModel = new RetailSkuGoodsModel();
|
|
$Config = $MerchantConfigModel->getFind(array('merchant_id' => self::$merchant_id));
|
|
$goods_id_gather = [];
|
|
foreach ($sellOrder as &$val) {
|
|
if (empty($val['goods_gifts_id'])) {
|
|
//非赠品
|
|
$v_dis = $val[$GoodsModel::VIP_RETAIL_STATE] == 1 ? $v_discount : 1;//初始商品会员折扣
|
|
if ($val['cashier_manual_discount'] < 1) {
|
|
if ($cashier_manual_discount_state != 1) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '您没有单品打折的权限';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
if ($manual_min_discount_state > $val['cashier_manual_discount']) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '商品-' . $val['goods_name'] . '-单品打折超过了最低折扣';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
$price = $val[$SellModel::ORIGINAL_PRICE];//原价
|
|
if (!empty($val[$SellModel::SKU_JSON_INFO])) {
|
|
//存在商品规格
|
|
$sku = json_decode($val[$SellModel::SKU_JSON_INFO], true);
|
|
if ($val[$GoodsModel::PLUS_MEM_STATUS] == 1) {
|
|
//开启plus会员价
|
|
$val[$GoodsModel::PLUS_PRICE] = $sku[$SkuModel::PLUS_PRICE];//plus会员价赋值
|
|
$val[$GoodsModel::PLUS_MEM_INTEGRAL] = $sku[$SkuModel::PLUS_MEM_INTEGRAL];//plus会员价赋值
|
|
}
|
|
if ($val[$GoodsModel::STORE_MEM_STATUS] == 1) {
|
|
//开启普通会员价
|
|
$val[$GoodsModel::STORE_MEM_PRICE] = $sku[$SkuModel::STORE_MEM_PRICE];//常规会员价赋值
|
|
$val[$GoodsModel::STORE_MEM_INTEGRAL] = $sku[$SkuModel::STORE_MEM_INTEGRAL];//常规会员价赋值
|
|
}
|
|
}
|
|
if (!empty($vip) && $vip['plus_type'] == 2 && $val['plus_mem_status'] == 1) {
|
|
//plus会员
|
|
if ($integral_cashing != 1 && $Config['integral_arrive_cash'] == 1 && $Config['marketing_methods'] == 2 && $val['plus_mem_integral'] > 0) {
|
|
//积分基于商品且设置了积分并且放弃使用积分,使用原价购买
|
|
$val[$SellModel::PLUS_VIP_PRICE] = 0;
|
|
$val[$SellModel::VIP_PRICE] = 0;
|
|
} else {
|
|
$val[$SellModel::PLUS_VIP_PRICE] = $val[$GoodsModel::PLUS_PRICE];//记录plus会员价
|
|
$price = $val[$SellModel::PLUS_VIP_PRICE];
|
|
$v_dis = 1;//plus会员价不享受会员折扣
|
|
}
|
|
} else if (!empty($vip) && $val['store_mem_status'] == 1) {
|
|
//常规会员
|
|
if ($integral_cashing != 1 && $Config['integral_arrive_cash'] == 1 && $Config['marketing_methods'] == 2 && $val['store_mem_integral'] > 0) {
|
|
//积分基于商品且设置了积分并且放弃使用积分兑换
|
|
$val[$SellModel::PLUS_VIP_PRICE] = 0;
|
|
$val[$SellModel::VIP_PRICE] = 0;
|
|
} else {
|
|
$val[$SellModel::VIP_PRICE] = $val[$GoodsModel::STORE_MEM_PRICE];//记录会员价
|
|
$price = $val[$SellModel::VIP_PRICE];
|
|
}
|
|
} else {
|
|
$val[$SellModel::PLUS_VIP_PRICE] = 0;
|
|
$val[$SellModel::VIP_PRICE] = 0;
|
|
}
|
|
$cashier_manual_discount = $val['cashier_manual_discount'];//收银员单品折扣
|
|
if ($store_manual_discount_state != 1 && $cashier_manual_discount < 1 && $cashier_manual_discount > 0) {
|
|
//未开启单品折上折并且进行了单品折扣
|
|
$v_dis = 1;//关闭会员打折
|
|
}
|
|
if ($store_preferential_state != 1 && $discount < 1) { // 未开启整单折上折,且进行了整单打折
|
|
$cashier_manual_discount = 1;//关闭单品打折
|
|
$v_dis = 1;//关闭会员打折
|
|
}
|
|
if (!empty($vid) && $v_dis < 1 && $val[$GoodsModel::VIP_RETAIL_STATE] == 1) {
|
|
//有会员信息 + 有折扣 + 该商品允许vip线下会员打折
|
|
if (($vip[$VipModel::PLUS_TYPE] == 2 && $val[$GoodsModel::PLUS_MEM_STATUS] == 2) || ($vip[$VipModel::PLUS_TYPE] == 3)) {
|
|
//开启会员打折
|
|
$price = round($price * $v_dis, 2);//计算打折之后的价格
|
|
$price = $price > 0.01 ? $price : 0.01;//打折之后单价最低为0.01元
|
|
}
|
|
}
|
|
$manual_price = round($price * $cashier_manual_discount, 2);//单品打折后单价
|
|
$manual_price = $manual_price > 0.01 ? $manual_price : 0.01;
|
|
if ($cashier_manual_discount < 1 && round($price - $manual_price - $manual_max_amount_state, 2) > 0 && $manual_max_amount_state > 0) {
|
|
$res['status'] = 0;
|
|
$res['message'] = '折扣值过低,优惠金额过大!';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$money = round($manual_price * $val[$SellModel::NUM], 2);//计算单品打折后总价
|
|
$goods_id_gather[] = [
|
|
'goods_id' => $val['goods_id'],
|
|
'sku_json_info'=>$val['sku_json_info']?$val['sku_json_info']:'',
|
|
'all_money' => $money
|
|
];
|
|
}
|
|
}
|
|
$result = $ShopCouponClass->verificationCouponTermVerify([
|
|
'shop_coupon' => $shop_coupon,
|
|
'verification_available_type' => 2,
|
|
'verification_store_id' => self::$store_id,
|
|
'order_money' => $order_money,
|
|
'sellDataArray' => $goods_id_gather
|
|
]);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
} |