小程序支付金额计算错误,提交订单结算页面的合计金额,没加运费啊,积分,优惠券

This commit is contained in:
sugar1569 2019-04-02 17:33:24 +08:00
parent 163426ed78
commit 686e876d2f
14 changed files with 243 additions and 84 deletions

View File

@ -32,7 +32,7 @@ class StoreCart extends ModelBasic
return self::setErrorInfo('该产品已下架或删除');
$userbuycount = StoreOrder::where(['uid'=>$uid,'paid'=>1,'seckill_id'=>$seckill_id])->count();
if($StoreSeckillinfo['num'] <= $userbuycount)
return self::setErrorInfo('每人限购'.$StoreSeckillinfo['num'].'件');
return self::setErrorInfo('每人限购'.$StoreSeckillinfo['num'].'件');
if(StoreSeckill::getProductStock($seckill_id) < $cart_num)
return self::setErrorInfo('该产品库存不足'.$cart_num);
$where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'seckill_id'=>$seckill_id];
@ -134,7 +134,7 @@ class StoreCart extends ModelBasic
}else if(!$product['is_show'] || $product['is_del'] || !$product['stock']){
$invalid[] = $cart;
//商品属性不对应
}else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique']) && !$cart['combination_id'] && !$cart['seckill_id']){
}else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique']) && !$cart['combination_id'] && !$cart['seckill_id']&& !$cart['bargain_id']){
$invalid[] = $cart;
//正常商品
}else{
@ -220,5 +220,27 @@ class StoreCart extends ModelBasic
return compact('valid','invalid');
}
/**
* TODO 判断购物车产品是否可以继续下单
* @param int $id
* @return bool|int|string
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function decideCartProductOverdue($id = 0){
if(!$id) return self::setErrorInfo('参数错误');
$cartInfo = self::where('id',$id)->field('cart_num,product_id,combination_id,seckill_id,bargain_id,product_attr_unique')->find();
if($cartInfo['combination_id']) return StoreCombination::isValidCartCombination($cartInfo['combination_id'],$cartInfo['cart_num']);
else if($cartInfo['seckill_id']) return StoreSeckill::isValidCartSeckill($cartInfo['seckill_id'],$cartInfo['cart_num']);
else if($cartInfo['bargain_id']) return StoreBargain::isValidCartBargain($cartInfo['bargain_id'],$cartInfo['cart_num']);
else if(strlen(trim($cartInfo['product_attr_unique'])) > 2){
if(!StoreProduct::isValidProduct($cartInfo['product_id'])) return self::setErrorInfo('该产品已下架或删除');
if(!StoreProductAttr::issetProductUnique($cartInfo['product_id'],$cartInfo['product_attr_unique'])) return self::setErrorInfo('请选择有效的产品属性');
if(StoreProduct::getProductStock($cartInfo['product_id'],$cartInfo['product_attr_unique']) < $cartInfo['cart_num']) return self::setErrorInfo('该产品库存不足'.$cartInfo['cart_num']);
return true;
}else return StoreProduct::isValidCartProduct($cartInfo['product_id'],$cartInfo['cart_num']);
}
}

View File

@ -52,7 +52,7 @@ class StoreCouponIssue extends ModelBasic
$issueCouponInfo['remain_count'] -= 1;
$res3 = false !== $issueCouponInfo->save();
}
$res = $res1 && $res2 & $res3;
$res = $res1 && $res2 && $res3;
self::checkTrans($res);
return $res;
}

View File

@ -127,6 +127,18 @@ class StoreCouponUser extends ModelBasic
return self::where('id',$id)->update(['status'=>1,'use_time'=>time()]);
}
/**
* TODO 恢复优惠券
* @param $id
* @return StoreCouponUser|bool
*/
public static function recoverCoupon($id)
{
$status = self::where('id',$id)->value('status');
if($status) return self::where('id',$id)->update(['status'=>0,'use_time'=>'']);
else return true;
}
public static function addUserCoupon($uid,$cid,$type = 'get')
{
$couponInfo = StoreCoupon::find($cid);

View File

@ -30,6 +30,7 @@ use service\RoutineTemplateService;
use think\Cache;
use think\Url;
use traits\ModelTrait;
use service\MiniProgramService;
class StoreOrder extends ModelBasic
{
@ -64,20 +65,20 @@ class StoreOrder extends ModelBasic
{
$storePostage = floatval(SystemConfigService::get('store_postage'))?:0;//邮费基础价
$storeFreePostage = floatval(SystemConfigService::get('store_free_postage'))?:0;//满额包邮
$totalPrice = self::getOrderTotalPrice($cartInfo);//获取订单总金额
$costPrice = self::getOrderCostPrice($cartInfo);//获取订单成本价
//如果满额包邮等于0
if(!$storeFreePostage) {
$totalPrice = floatval(self::getOrderTotalPrice($cartInfo));//获取订单总金额
$costPrice = floatval(self::getOrderCostPrice($cartInfo));//获取订单成本价
//如果订单金额大于满额包邮 邮费等于0
if($totalPrice >= $storeFreePostage) {
$storePostage = 0;
}else{
foreach ($cartInfo as $cart){
if(!$cart['productInfo']['is_postage'])//若果产品不包邮
$storePostage = bcadd($storePostage,$cart['productInfo']['postage'],2);
$storePostage = bcadd($storePostage,floatval($cart['productInfo']['postage']),2);
}
if($storeFreePostage <= $totalPrice) $storePostage = 0;//如果总价大于等于满额包邮 邮费等于0
}
// $totalPrice = bcadd($totalPrice,$storePostage,2);
$totalPrice = bcadd($totalPrice,$storePostage,2);
return compact('storePostage','storeFreePostage','totalPrice','costPrice');
}
@ -210,6 +211,9 @@ class StoreOrder extends ModelBasic
if(!UserAddress::be(['uid'=>$uid,'id'=>$addressId,'is_del'=>0]) || !($addressInfo = UserAddress::find($addressId)))
return self::setErrorInfo('地址选择有误!');
//是否包邮
//if((isset($other['offlinePostage']) && $other['offlinePostage'] && $payType == 'offline')) $payPostage = 0;
//$payPrice = bcadd($payPrice,$payPostage,2);
//使用优惠劵
$res1 = true;
if($couponId){
@ -217,22 +221,23 @@ class StoreOrder extends ModelBasic
if(!$couponInfo) return self::setErrorInfo('选择的优惠劵无效!');
if($couponInfo['use_min_price'] > $payPrice)
return self::setErrorInfo('不满足优惠劵的使用条件!');
$payPrice = bcsub($payPrice,$couponInfo['coupon_price'],2);
$res1 = StoreCouponUser::useCoupon($couponId);
$couponPrice = $couponInfo['coupon_price'];
if($payPrice < $couponInfo['coupon_price']) {
$couponPrice = $payPrice;
$payPrice = 0;
}else {
$payPrice = bcsub($payPrice,$couponInfo['coupon_price'],2);
$couponPrice = $couponInfo['coupon_price'];
}
}else{
$couponId = 0;
$couponPrice = 0;
}
if(!$res1) return self::setErrorInfo('使用优惠劵失败!');
//是否包邮
if((isset($other['offlinePostage']) && $other['offlinePostage'] && $payType == 'offline')) $payPostage = 0;
$payPrice = bcadd($payPrice,$payPostage,2);
//积分抵扣
$res2 = true;
if($useIntegral && $userInfo['integral'] > 0){
if($useIntegral && $userInfo['integral'] > 0 && $payPrice > 0){
$deductionPrice = bcmul($userInfo['integral'],$other['integralRatio'],2);
if($deductionPrice < $payPrice){
$payPrice = bcsub($payPrice,$deductionPrice,2);
@ -244,7 +249,7 @@ class StoreOrder extends ModelBasic
$res2 = false !== User::bcDec($userInfo['uid'],'integral',$usedIntegral,'uid');
$payPrice = 0;
}
$res2 = $res2 && false != UserBill::expend('积分抵扣',$uid,'integral','deduction',$usedIntegral,$key,$userInfo['integral'],'购买商品使用'.floatval($usedIntegral).'积分抵扣'.floatval($deductionPrice).'元');
$res2 = $res2 && false != UserBill::expend('积分抵扣',$uid,'integral','deduction',$usedIntegral,$key,bcsub($userInfo['integral'],$usedIntegral,2),'购买商品使用'.floatval($usedIntegral).'积分抵扣'.floatval($deductionPrice).'元');
}else{
$deductionPrice = 0;
$usedIntegral = 0;
@ -290,13 +295,6 @@ class StoreOrder extends ModelBasic
$order = self::set($orderInfo);
if(!$order)return self::setErrorInfo('订单生成失败!');
$res5 = true;
foreach ($cartInfo as $cart){
//减库存加销量
if($combinationId) $res5 = $res5 && StoreCombination::decCombinationStock($cart['cart_num'],$combinationId);
else if($seckill_id) $res5 = $res5 && StoreSeckill::decSeckillStock($cart['cart_num'],$seckill_id);
else if($bargain_id) $res5 = $res5 && StoreBargain::decBargainStock($cart['cart_num'],$bargain_id);
else $res5 = $res5 && StoreProduct::decProductStock($cart['cart_num'],$cart['productInfo']['id'],isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique']:'');
}
//保存购物车商品信息
$res4 = false !== StoreOrderCartInfo::setCartInfo($order['id'],$cartInfo);
//购物车状态修改
@ -336,7 +334,8 @@ class StoreOrder extends ModelBasic
if($orderInfo['paid']) exception('支付已支付!');
if($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
$openid = WechatUser::getOpenId($orderInfo['uid']);
return RoutineService::payRoutine($openid,$orderInfo['order_id'],$orderInfo['pay_price'],'productr',SystemConfigService::get('site_name'));
return MiniProgramService::jsPay($openid,$orderInfo['order_id'],$orderInfo['pay_price'],'productr',SystemConfigService::get('site_name'));//2.5.36
// return RoutineService::payRoutine($openid,$orderInfo['order_id'],$orderInfo['pay_price'],'productr',SystemConfigService::get('site_name'));
}
//TODO 余额支付
public static function yuePay($order_id,$uid,$formId = '')
@ -350,7 +349,8 @@ class StoreOrder extends ModelBasic
return self::setErrorInfo('余额不足'.floatval($orderInfo['pay_price']));
self::beginTrans();
$res1 = false !== User::bcDec($uid,'now_money',$orderInfo['pay_price'],'uid');
$res2 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$userInfo['now_money'],'余额支付'.floatval($orderInfo['pay_price']).'元购买商品');
$balance = bcsub($userInfo['now_money'],$orderInfo['pay_price'],2);
$res2 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$balance,'余额支付'.floatval($orderInfo['pay_price']).'元购买商品');
$res3 = self::paySuccess($order_id,'yue',$formId);//余额支付成功
try{
// HookService::listen('yue_pay_product',$userInfo,$orderInfo,false,PaymentBehavior::class);
@ -432,12 +432,21 @@ class StoreOrder extends ModelBasic
$order = self::where('order_id',$orderId)->find();
$resPink = true;
$res1 = self::where('order_id',$orderId)->update(['paid'=>1,'pay_type'=>$paytype,'pay_time'=>time()]);//订单改为支付
$cartInfo = self::getDb('StoreOrderCartInfo')->where('oid',$order['id'])->column('cart_info','unique')?:[];
foreach ($cartInfo as $k=>&$cart) $cart = json_decode($cart, true);
$res2 = true;
foreach ($cartInfo as $k=>&$cart){ //减库存加销量
if($cart['combination_id']) $res2 = $res2 && StoreCombination::decCombinationStock($cart['cart_num'],$cart['combination_id']);
else if($cart['seckill_id']) $res2 = $res2 && StoreSeckill::decSeckillStock($cart['cart_num'],$cart['seckill_id']);
else if($cart['bargain_id']) $res2 = $res2 && StoreBargain::decBargainStock($cart['cart_num'],$cart['bargain_id']);
else $res2 = $res2 && StoreProduct::decProductStock($cart['cart_num'],$cart['productInfo']['id'],isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique']:'');
}
User::bcInc($order['uid'],'pay_count',1,'uid');
if($order->combination_id && $res1 && !$order->refund_status) $resPink = StorePink::createPink($order);//创建拼团
$oid = self::where('order_id',$orderId)->value('id');
StoreOrderStatus::status($oid,'pay_success','用户付款成功');
RoutineTemplate::sendOrderSuccess($formId,$orderId);
$res = $res1 && $resPink;
$res = $res1 && $resPink && $res2;
return false !== $res;
}
@ -525,11 +534,37 @@ class StoreOrder extends ModelBasic
$order = self::getUserOrderDetail($uid,$uni);
if(!$order) return self::setErrorInfo('订单不存在!');
$order = self::tidyOrder($order);
if($order['_status']['_type'] != 0 && $order['_status']['_type']!= -2 && $order['_status']['_type'] != 4)
if($order['_status']['_type'] != 0 && $order['_status']['_type']!= -2 && $order['_status']['_type'] != 4)
return self::setErrorInfo('该订单无法删除!');
if(false !== self::edit(['is_del'=>1],$order['id'],'id') &&
if($order['_status']['_type'] == 4 && false !== self::edit(['is_del'=>1],$order['id'],'id') &&
false !==StoreOrderStatus::status($order['id'],'remove_order','删除订单'))
return true;
else if($order['_status']['_type'] != 4){//TODO 退款 未支付订单 删除退会积分和优惠券
self::beginTrans();
$res1 = self::edit(['is_del'=>1],$order['id'],'id');
$res2 = StoreOrderStatus::status($order['id'],'remove_order','删除订单');
$res3 = true;
$res4 = true;
$couponPrice = 0;
if($order['coupon_id']) {
$res3 = StoreCouponUser::recoverCoupon($order['coupon_id']);
$couponPrice = $order['coupon_price'];
$res4 = self::edit(['coupon_price'=>0.00,'coupon_id'=>0,'pay_price'=>bcadd($order['pay_price'],$couponPrice,2)],$order['id'],'id');
}
$res5 = true;
$res6 = true;
$res7 = true;
if($order['use_integral']) {
$userInfo = User::getUserInfo($order['uid']);
$res5 = User::recoverOrderIntegral($order['uid'],$order['use_integral']);// TODO 退会积分到用户
$res6 = self::edit(['deduction_price'=>0.00,'use_integral'=>0.00,'back_integral'=>$order['use_integral'],'pay_price'=>bcadd($couponPrice,bcadd($order['pay_price'],$order['deduction_price'],2),2)],$order['id'],'id'); // TODO 修改积分为空
$balance = bcadd($userInfo['integral'],$order['use_integral'],2);
$res7 = UserBill::income('积分退回',$order['uid'],'integral','recover_deduction',$order['use_integral'],$order['unique'],$balance,'退回购买商品使用'.floatval($order['use_integral']).'积分抵扣'.floatval($order['deduction_price']).'元');
}
$res = $res1 && $res2 && $res3 && $res4 && $res5 && $res6 && $res7;
self::checkTrans($res);
return $res;
}
else
return self::setErrorInfo('订单删除失败!');
}
@ -669,7 +704,7 @@ class StoreOrder extends ModelBasic
public static function getUserOrderList($uid,$status = '',$first = 0,$limit = 8)
{
$list = self::statusByWhere($status)->where('is_del',0)->where('uid',$uid)
->field('seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type')
->field('add_time,seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type')
->order('add_time DESC')->limit($first,$limit)->select()->toArray();
foreach ($list as $k=>$order){
$list[$k] = self::tidyOrder($order,true);
@ -722,7 +757,7 @@ class StoreOrder extends ModelBasic
$noBuy = self::where('uid',$uid)->where('paid',0)->where('is_del',0)->where('pay_type','<>','offline')->count();
$noPostageNoPink = self::where('o.uid',$uid)->alias('o')->where('o.paid',1)->where('o.pink_id',0)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
$noPostageYesPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',2)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
$noPostage = bcadd($noPostageNoPink,$noPostageYesPink);
$noPostage = (int)bcadd($noPostageNoPink,$noPostageYesPink,0);
$noTake = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',1)->where('pay_type','<>','offline')->count();
$noReply = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',2)->count();
$noPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',1)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
@ -736,7 +771,7 @@ class StoreOrder extends ModelBasic
$userInfo = User::getUserInfo($order['uid']);
ModelBasic::beginTrans();
$res1 = false != User::where('uid',$userInfo['uid'])->update(['integral'=>bcadd($userInfo['integral'],$order['gain_integral'],2)]);
$res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],$userInfo['integral'],'购买商品赠送'.floatval($order['gain_integral']).'积分');
$res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],bcadd($userInfo['integral'],$order['gain_integral'],2),'购买商品赠送'.floatval($order['gain_integral']).'积分');
$res = $res1 && $res2;
ModelBasic::checkTrans($res);
return $res;

View File

@ -213,7 +213,7 @@ class StoreOrder extends ModelBasic
$res2 = false !== User::bcDec($userInfo['uid'],'integral',$usedIntegral,'uid');
$payPrice = 0;
}
$res2 = $res2 && false != UserBill::expend('积分抵扣',$uid,'integral','deduction',$usedIntegral,$key,$userInfo['integral'],'购买商品使用'.floatval($usedIntegral).'积分抵扣'.floatval($deductionPrice).'元');
$res2 = $res2 && false != UserBill::expend('积分抵扣',$uid,'integral','deduction',$usedIntegral,$key,bcsub($userInfo['integral'],$usedIntegral,2),'购买商品使用'.floatval($usedIntegral).'积分抵扣'.floatval($deductionPrice).'元');
}else{
$deductionPrice = 0;
$usedIntegral = 0;
@ -319,7 +319,7 @@ class StoreOrder extends ModelBasic
return self::setErrorInfo('余额不足'.floatval($orderInfo['pay_price']));
self::beginTrans();
$res1 = false !== User::bcDec($uid,'now_money',$orderInfo['pay_price'],'uid');
$res2 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$userInfo['now_money'],'余额支付'.floatval($orderInfo['pay_price']).'元购买商品');
$res2 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],bcsub($userInfo['now_money'],$orderInfo['pay_price'],2),'余额支付'.floatval($orderInfo['pay_price']).'元购买商品');
$res3 = self::paySuccess($order_id);
try{
HookService::listen('yue_pay_product',$userInfo,$orderInfo,false,PaymentBehavior::class);
@ -684,7 +684,7 @@ class StoreOrder extends ModelBasic
$noBuy = self::where('uid',$uid)->where('paid',0)->where('is_del',0)->where('pay_type','<>','offline')->where('refund_status',0)->count();
$noPostageNoPink = self::where('o.uid',$uid)->alias('o')->where('o.paid',1)->where('o.pink_id',0)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->where('o.refund_status',0)->count();
$noPostageYesPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',2)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.refund_status',0)->where('o.pay_type','<>','offline')->count();
$noPostage = bcadd($noPostageNoPink,$noPostageYesPink);
$noPostage = bcadd($noPostageNoPink,$noPostageYesPink,0);
$noTake = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',1)->where('pay_type','<>','offline')->where('refund_status',0)->count();
$noReply = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',2)->where('refund_status',0)->count();
$noPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',1)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->where('o.refund_status',0)->count();
@ -697,7 +697,7 @@ class StoreOrder extends ModelBasic
$userInfo = User::getUserInfo($order['uid']);
ModelBasic::beginTrans();
$res1 = false != User::where('uid',$userInfo['uid'])->update(['integral'=>bcadd($userInfo['integral'],$order['gain_integral'],2)]);
$res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],$userInfo['integral'],'购买商品赠送'.floatval($order['gain_integral']).'积分');
$res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],bcadd($userInfo['integral'],$order['gain_integral'],2),'购买商品赠送'.floatval($order['gain_integral']).'积分');
$res = $res1 && $res2;
ModelBasic::checkTrans($res);
return $res;

View File

@ -13,20 +13,29 @@ use app\routine\model\store\StoreOrder as StoreOrderRoutineModel;
use app\wap\model\store\StoreOrder as StoreOrderWapModel;
use app\wap\model\user\UserRecharge;
use service\HookService;
use service\RoutineRefund;
use service\WechatService;
use service\MiniProgramService;
class PaymentBehavior
{
/**
* 下单成功之后
* 公众号下单成功之后
* @param $order
* @param $prepay_id
*/
public static function wechatPaymentPrepare($order, $prepay_id)
{
}
/**
* 小程序下单成功之后
* @param $order
* @param $prepay_id
*/
public static function wechatPaymentPrepareProgram($order, $prepay_id)
{
}
/**
@ -121,7 +130,8 @@ class PaymentBehavior
public static function routinePayOrderRefund($orderNo, array $opt)
{
$refundDesc = isset($opt['desc']) ? $opt['desc'] : '';
$res = RoutineRefund::doRefund($opt['pay_price'],$opt['refund_price'],$orderNo,'',$orderNo,$refundDesc);
$res = MiniProgramService::payOrderRefund($orderNo,$opt);//2.5.36
// $res = RoutineRefund::doRefund($opt['pay_price'],$opt['refund_price'],$orderNo,'',$orderNo,$refundDesc);
}
/**

View File

@ -1,19 +1,3 @@
{"navigationBarTitleText": "优惠券",
"list": [
{
"term": "满1000元使用",
"time": "2017/09/26至2017/10/26使用",
"money": "500"
},
{
"term": "满1000元使用",
"time": "2017/09/26至2017/10/26使用",
"money": "500"
},
{
"term": "满1000元使用",
"time": "2017/09/26至2017/10/26使用",
"money": "500"
}
]
{
"navigationBarTitleText": "优惠券"
}

View File

@ -10,15 +10,16 @@
<view class='coupon-ul'>
<block wx:for="{{couponArray}}">
<view class='coupon-li flex {{(item.status==1||item.status==2)?"coupon-use":""}}'>
<view class='coupon-text {{(!item.status)?"use-text":""}}'>
<view class='coupon-text {{(item.status)?"use-text":""}}'>
<view class='coupon-term'>满{{item.use_min_price}}元使用</view>
<view class='coupon-time'>{{item.add_time}}至{{item.end_time}}使用</view>
</view>
<view class='coupon-text2'>
<view class='coupon-text2 flex'>
<view class='coupon-money'>¥<text class='coupon-num'>{{item.coupon_price}}</text></view>
<view class='coupon-but {{(item.status==1||item.status==-1)?"use-but":""}}' wx:if="{{item.status==0}}" >未使用</view>
<view class='coupon-but {{(item.status==1||item.status==-1)?"coupon-use":""}}' wx:if="{{item.status==1}}" >已使用</view>
<view class='coupon-but {{(item.status==1||item.status==-1)?"use-text":""}}' wx:if="{{item.status==2}}" >已过期</view>
<view class='coupon-but ' wx:if="{{item.status==0}}" >未使用</view>
<view class='coupon-but use-text' wx:if="{{item.status==1}}" >已使用</view>
<view class='coupon-but use-text' wx:if="{{item.status==2}}" >已过期</view>
</view>
<view class='{{item.status==0?"coupon-new":""}}'></view>
</view>

File diff suppressed because one or more lines are too long

View File

@ -33,7 +33,9 @@ Page({
addressInfo:[],
mark:'',
payType:'weixin',
useIntegral:''
useIntegral:false,
useInegealOrder:0,
statusIntegral: false,
},
/**
* 生命周期函数--监听页面加载
@ -73,6 +75,53 @@ Page({
that.getCouponRope();
},
//使用积分
checkboxChange: function () {
var that = this;
that.setData({
statusIntegral: !that.data.statusIntegral,//更改是否勾选积分
useIntegral: !that.data.useIntegral //是否使用积分
});
//用户所有计算积分抵扣金额
var integralCountPrice = (Number(that.data.userInfo.integral) * Number(that.data.integralRatio)).toFixed(2);
console.log(that.data.userInfo.integral);
console.log(integralCountPrice);
//如果积分抵扣金额能大于订单总金额
if (Number(integralCountPrice) >= Number(that.data.totalPrice) && that.data.statusIntegral) {
var iCountPrice = Number(that.data.totalPrice);/* priceGroup. */
var useinegeal = (Number(that.data.totalPrice) / Number(that.data.integralRatio)).toFixed(2);
}else{
//实际抵扣的积分金额
if (that.data.useInegealOrder > 0){
var iCountPrice = (Number(that.data.useInegealOrder) * Number(that.data.integralRatio)).toFixed(2);
var useinegeal = that.data.useInegealOrder;
}else{
var iCountPrice = (Number(that.data.userInfo.integral) * Number(that.data.integralRatio)).toFixed(2);
var useinegeal = Number(that.data.userInfo.integral);
}
}
//如果使用积分
console.log(useinegeal);
console.log(that.data.useInegealOrder);
console.log(that.data.totalPrice);
console.log(iCountPrice);
var totalPrice = 0;
if ((Number(that.data.totalPrice) - Number(iCountPrice)).toFixed(2) > 0) totalPrice = (Number(that.data.totalPrice) - Number(iCountPrice)).toFixed(2);
if (that.data.statusIntegral) {
that.setData({
priceIntegral: '-' + useinegeal,
totalPrice: totalPrice,
useInegealOrder: useinegeal
});
console.log(that.data.totalPrice);
} else {
console.log(that.data.totalPrice);
that.setData({
priceIntegral: '',
totalPrice: Number(Number(that.data.totalPrice) + Number(iCountPrice)).toFixed(2)
});
}
},
bindHideKeyboard:function(e){
this.setData({
mark: e.detail.value
@ -86,7 +135,7 @@ Page({
subOrder:function(e){
var that = this;
var header = {
'content-type': 'application/x-www-form-urlencoded',
'content-type': 'application/json',
};
if (that.data.payType == ''){
wx.showToast({
@ -166,7 +215,7 @@ Page({
} else if (res.data.code == 200 && res.data.data.status == 'WECHAT_PAY'){
var jsConfig = res.data.data.result.jsConfig;
wx.requestPayment({
timeStamp: jsConfig.timeStamp,
timeStamp: jsConfig.timestamp,
nonceStr: jsConfig.nonceStr,
package: jsConfig.package,
signType: jsConfig.signType,
@ -221,6 +270,7 @@ Page({
})
}
},
//使用优惠券
getCouponRope:function(){
var that = this;
if (that.data.couponId){
@ -232,10 +282,15 @@ Page({
},
success: function (res) {
if (res.data.code == 200) {
//原价
var totalPrice = that.data.totalPrice;
if (Number(res.data.data.coupon_price) > 0){
totalPrice = Number(that.data.totalPrice) - Number(res.data.data.coupon_price);
}
totalPrice = totalPrice > 0 ? totalPrice : 0;
that.setData({
couponInfo: res.data.data,
// couponPrice: '-' + res.data.data.coupon_price,
totalPrice: Number(that.data.totalPrice) - Number(res.data.data.coupon_price)
totalPrice: totalPrice
})
}else{
that.setData({
@ -335,7 +390,7 @@ Page({
offlinePostage: res.data.data.offlinePostage,
orderKey: res.data.data.orderKey,
priceGroup: res.data.data.priceGroup,
totalPrice: Number(res.data.data.priceGroup.totalPrice) + Number(res.data.data.priceGroup.storePostage),
totalPrice: res.data.data.priceGroup.totalPrice,
cartId: res.data.data.cartId,
seckillId: res.data.data.seckill_id,
usableCoupon: res.data.data.usableCoupon
@ -358,9 +413,9 @@ Page({
BargainId: BargainId,
combinationId:combinationId
})
console.log(that.data.BargainId);
console.log(that.data.seckillId);
console.log(that.data.combinationId);
// console.log(that.data.BargainId);
// console.log(that.data.seckillId);
// console.log(that.data.combinationId);
},
/**
* 生命周期函数--监听页面初次渲染完成

View File

@ -28,11 +28,21 @@
<text>运费</text>
<view class='select-btn'>快递<text>¥{{priceGroup.storePostage}}</text></view>
</view>
<view class='text-item flex' wx:if="{{!seckillId && !BargainId && !combinationId}}">
<view class='text-item flex' wx:if="{{seckillId == 0 && BargainId == 0 && combinationId == 0}}">
<text>优惠券</text>
<view class='sale-btn' bindtap='getCoupon' wx:if="{{couponId}}">满{{couponInfo.use_min_price}}减{{couponInfo.coupon_price}}</view>
<view class='sale-btn' bindtap='getCoupon' wx:else>选择优惠券</view>
</view>
<view class='text-item flex' wx:if="{{seckillId == 0 && BargainId == 0 && combinationId == 0}}">
<view>
<text>可用积分:{{userInfo.integral}}</text>
<text wx:if="{{statusIntegral == true}}" style='color:red;'>{{priceIntegral}}</text>
</view>
<checkbox-group bindchange="checkboxChange">
<checkbox value="1"/>
</checkbox-group>
</view>
<view class='text-item flex inp-wrapper'>
<text>买家留言</text>
<view class='inp-btn'><input bindinput='bindHideKeyboard' value="" name="mark" placeholder='请填写自己需要注明的信息' ></input></view>

View File

@ -58,7 +58,7 @@ radio .wx-radio-input.wx-radio-input-checked::before{
transform:translate(-50%, -50%) scale(1);
-webkit-transform:translate(-50%, -50%) scale(1);
}
checkbox .wx-checkbox-input{border-radius: 50%;width:40rpx;height: 40rpx;}
.foot{position: fixed; left: 0; bottom: 0; width: 100%; border-top: 1px solid #eee; background-color: #fff; justify-content: space-between; align-items: center;}
.foot .submit-btn{width: 275rpx; height: 100rpx; line-height: 100rpx; background-color: #ff3d3d; color: #fff; text-align: center; border-radius:0;
}

View File

@ -48,7 +48,7 @@ Page({
wx.showActionSheet({
itemList: ['微信支付', '余额支付'],
success(res) {
console.log(res.tapIndex)
// console.log(res.tapIndex)
if (res.tapIndex == 0) {//微信支付
wx.request({
url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid + '&uni=' + e.target.dataset.id + '&paytype=weixin',
@ -57,9 +57,9 @@ Page({
var data = res.data.data;
if (res.data.code == 200) {
var jsConfig = res.data.data.result.jsConfig;
console.log(jsConfig);
// console.log(jsConfig);
wx.requestPayment({
timeStamp: jsConfig.timeStamp,
timeStamp: jsConfig.timestamp,
nonceStr: jsConfig.nonceStr,
package: jsConfig.package,
signType: jsConfig.signType,
@ -95,6 +95,12 @@ Page({
}
},
})
}else{
wx.showToast({
title: res.data.msg,
icon: 'fail',
duration: 2000
})
}
},
fail: function (res) {
@ -157,7 +163,7 @@ Page({
var jsConfig = res.data.data.result.jsConfig;
console.log(jsConfig);
wx.requestPayment({
timeStamp: jsConfig.timeStamp,
timeStamp: jsConfig.timestamp,
nonceStr: jsConfig.nonceStr,
package: jsConfig.package,
signType: jsConfig.signType,
@ -345,6 +351,28 @@ Page({
url: '/pages/index/index'
})
},
goAgain:function(e){
var that = this;
var uni = e.currentTarget.dataset.uni;
wx.request({
url: app.globalData.url + '/routine/auth_api/again_order?uid=' + app.globalData.uid,
data: { uni: uni },
method: 'get',
success: function (res) {
if (res.data.code == 200) {
wx.navigateTo({
url: '/pages/order-confirm/order-confirm?id=' + res.data.data,
})
} else {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
}
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/

View File

@ -52,8 +52,9 @@
<image src='{{url}}{{item.productInfo.image}}'></image>
<view class='pro-info'>
<view class='title'>{{item.productInfo.store_name}}</view>
<view class='res'>{{item.productInfo.store_name}}</view>
<view class='price'><text>¥</text>{{item.productInfo.price}}<text class='count'>x{{item.cart_num}}</text></view>
<view class='res' wx:if="{{item.productInfo.attrInfo}}">{{item.productInfo.attrInfo.suk}}</view>
<view class='price' wx:if="{{item.productInfo.attrInfo}}"><text>¥</text>{{item.productInfo.attrInfo.price}}<text class='count'>x{{item.cart_num}}</text></view>
<view class='price' wx:else><text>¥</text>{{item.productInfo.price}}<text class='count'>x{{item.cart_num}}</text></view>
</view>
<navigator wx:if="{{ordercon._status._type==3}}" hover-class="none" url='/pages/comment-con/comment-con?unique={{item.unique}}&uni={{ordercon.order_id}}' class='assess-btn'>评价</navigator>
<view wx:elif="{{ordercon._status._type==4}}" class='assess-btn off'>已评价</view>
@ -85,7 +86,7 @@
</view>
<view class='infos flex'>
<text>折扣价</text>
<text class='count'>¥{{ordercon.deduction_price}}</text>
<text class='count'>¥{{ordercon.favourable_price}}</text>
</view>
</view>
</view>
@ -117,6 +118,6 @@
<navigator wx:if="{{ordercon._status._type==2 && ordercon.delivery_type == 'express'}}" hover-class="none" url='/pages/logistics/logistics?orderId={{ordercon.order_id}}'><view class='delete-btn' >查看物流</view></navigator>
<view wx:if="{{ordercon._status._type==2}}" class='pay-btn' bindtap='confirmOrder' data-uni='{{ordercon.order_id}}'>确认收货</view>
<view wx:if="{{ordercon._status._type==4 || ordercon._status._type==0}}" class='delete-btn' bindtap='delOrder' data-uni='{{ordercon.order_id}}'>删除订单</view>
<navigator wx:if="{{!ordercon.seckill_id && !ordercon.bargain_id && !ordercon.combination_id && (ordercon._status._type==3||ordercon._status._type==4)}}" hover-class="none" bindtap='goIndex'><view class='pay-btn'>再次购买</view></navigator>
<navigator wx:if="{{!ordercon.seckill_id && !ordercon.bargain_id && !ordercon.combination_id && (ordercon._status._type==3||ordercon._status._type==4)}}" hover-class="none"><view class='pay-btn' bindtap='goAgain' data-uni='{{ordercon.order_id}}'>再次购买</view></navigator>
</view>
<include src="/pages/home/home.wxml"/>