/** * 生成订单总计详细 * @params object 控制器 * @params object cart objects * @params array sdf array */ public function trade_total_method($params) { $total_fee = $params['total_fee']; $items_weight = $params['total_weight']; $dlyTmplId = $params['template_id']; $shopId = $params['shop_id']; $region_id = $params['region_id']; $usedCartPromotionWeight = $params['usedCartPromotionWeight']; $discount_fee = $params['discount_fee']; if ($dlyTmplId && $region_id) { $params = array('template_id' => $dlyTmplId, 'weight' => $items_weight, 'areaIds' => $region_id); // 免运费促销 优惠前的运费 $beforePromotion_post_fee = app::get('systrade')->rpcCall('logistics.fare.count', $params); if ($usedCartPromotionWeight > 0) { // 免运费促销 优惠后的运费 $minusWeight = ecmath::number_minus(array($items_weight, $usedCartPromotionWeight)); if ($minusWeight > 0) { $params['weight'] = $minusWeight; $post_fee = app::get('systrade')->rpcCall('logistics.fare.count', $params); } else { $post_fee = 0; } } else { // 没有免运费的运费 $post_fee = $beforePromotion_post_fee; } if ($post_fee < 0) { $post_fee = 0; } } // $objMath = kernel::single('ectools_math'); $payment = ecmath::number_plus(array($total_fee, $post_fee)); $payment = ecmath::number_minus(array($payment, $discount_fee)); if ($payment < 0) { $payment = 0.01; //不可以有0元订单,最小值为0.01;后续改造 } //计算商品总额所获积分 $totalFee = $payment - $post_fee; $subtotal_obtain_point = app::get('systrade')->rpcCall('user.pointcount', array('money' => $totalFee)); $payment_detail = array('total_fee' => $total_fee, 'post_fee' => $post_fee, 'payment' => $payment, 'discount_fee' => $discount_fee, 'consume_point_fee' => $subtotal_consume_point, 'obtain_point_fee' => $subtotal_obtain_point); return $payment_detail; }
public function _makeCouponCode($params, $gen_quantity) { $couponInfo = app::get('syspromotion')->rpcCall('promotion.coupon.get', array('coupon_id' => $params['coupon_id'])); if (!$couponInfo) { throw new \LogicException('无此优惠券!'); } if ($couponInfo['cansend_start_time'] > time()) { throw new \LogicException('优惠券领取时间尚未开始,不能领取!'); } if ($couponInfo['cansend_end_time'] < time()) { throw new \LogicException('优惠券领取时间已过,不能领取!'); } if ($couponInfo['canuse_end_time'] < time()) { throw new \LogicException('优惠券已过期,无法领取!'); } // 已领优惠券和总领次数顺序不要颠倒 if (ecmath::number_plus(array(intval($gen_quantity), $couponInfo['send_couponcode_quantity'])) > $couponInfo['max_gen_quantity']) { throw new \LogicException('优惠券已经领完!'); } if ($couponInfo['userlimit_quantity'] <= $params['old_quantity']) { throw new \LogicException('您的领用次数已过!'); } $valid_grade = explode(',', $couponInfo['valid_grade']); if (!in_array($params['grade_id'], $valid_grade)) { throw new \LogicException('您的会员等级不可以领取此优惠券!'); } $prefix = $couponInfo['coupon_prefix']; $key = $couponInfo['coupon_key']; $iNo = bcadd(intval($gen_quantity), $couponInfo['send_couponcode_quantity'], 0); $coupon_code_count_len = 5; $coupon_code_encrypt_len = 5; // if ($this->app->getConf('coupon.code.count_len') >= strlen(strval($iNo))) { if ($coupon_code_count_len >= strlen(strval($iNo))) { $iNo = str_pad($this->dec2b36($iNo), $coupon_code_count_len, '0', STR_PAD_LEFT); $checkCode = md5($key . $iNo . $prefix); // $checkCode = strtoupper(substr($checkCode, 0, $this->app->getConf('coupon.code.encrypt_len'))); $checkCode = strtoupper(substr($checkCode, 0, $coupon_code_encrypt_len)); $memberCouponCode = $couponInfo['coupon_code'] = $prefix . $checkCode . $iNo; // $objMdlCoupon = app::get('syspromotion')->model('coupon'); $db = app::get('syspromotion')->model('coupon')->database(); $sqlStr = "UPDATE syspromotion_coupon SET send_couponcode_quantity=ifnull(send_couponcode_quantity,0)+? WHERE coupon_id=? "; if ($db->executeUpdate($sqlStr, [$gen_quantity, $params['coupon_id']])) { return $couponInfo; } else { return false; } } else { throw new \LogicException('优惠券已领完!'); return false; } }
public function checkCouponApply($user_id, $coupon_code, $cartItemsArray, &$couponInfo) { $filter['user_id'] = $user_id; $filter['coupon_code'] = $coupon_code; $userCoupon = app::get('syspromotion')->rpcCall('user.coupon.get', $filter); if (!$userCoupon || !$userCoupon['coupon_id']) { return 0; } if (!$userCoupon['is_valid']) { return 0; } $objMdlCoupon = app::get('syspromotion')->model('coupon'); $couponInfo = $objMdlCoupon->getRow('*', array('coupon_id' => $userCoupon['coupon_id'])); if (!$couponInfo || $couponInfo['coupon_status'] != 'agree') { return 0; } $now = time(); if ($now <= $couponInfo['canuse_start_time']) { return 0; } if ($now >= $couponInfo['canuse_end_time']) { return 0; } $objMdlCouponItem = app::get('syspromotion')->model('coupon_item'); $couponItems = $objMdlCouponItem->getList('item_id', array('coupon_id' => $userCoupon['coupon_id'])); $couponItemsIdArr = array_column($couponItems, 'item_id'); $validItemTotalFee = array(); foreach ($cartItemsArray as $v) { if (in_array($v['item_id'], $couponItemsIdArr)) { $validItemTotalFee[] = $v['total_price']; } } $validTotalMoney = ecmath::number_plus($validItemTotalFee); if ($validTotalMoney < $couponInfo['limit_money']) { return 0; } return true; }