Beispiel #1
0
 public function apply($params)
 {
     $fulldiscountInfo = app::get('syspromotion')->model('fulldiscount')->getRow('*', array('fulldiscount_id' => $params['fulldiscount_id']));
     if (!$fulldiscountInfo || $fulldiscountInfo['fulldiscount_status'] != 'agree') {
         return 0;
         // throw new \LogicException('不能使用此促销!');
     }
     $now = time();
     if ($now <= $fulldiscountInfo['start_time']) {
         return 0;
         // throw new \LogicException('尚未开始!');
     }
     if ($now >= $fulldiscountInfo['end_time']) {
         return 0;
         // throw new \LogicException('已经结束!');
     }
     $applyNum = app::get('syspromotion')->rpcCall('trade.promotion.applynum', array('promotion_id' => $params['promotion_id']));
     if ($applyNum >= $fulldiscountInfo['join_limit']) {
         return 0;
         // throw new \LogicException('可参与的满折次数已经用完!');
     }
     $valid_grade = explode(',', $fulldiscountInfo['valid_grade']);
     $gradeInfo = app::get('syspromotion')->rpcCall('user.grade.basicinfo');
     if (!in_array($gradeInfo['grade_id'], $valid_grade)) {
         return 0;
         // throw new \LogicException('您的当前会员等级不可参加此促销!');
     }
     // 满折金额的规则检验
     $rule = explode(',', $fulldiscountInfo['condition_value']);
     $ruleArray = array();
     foreach ($rule as $k => $v) {
         $tmpFulldiscountValue = explode('|', $v);
         $ruleArray['full'][$k] = $tmpFulldiscountValue['0'];
         $ruleArray['discount'][$k] = $tmpFulldiscountValue['1'];
     }
     $ruleLength = count($ruleArray['full']);
     if ($params['forPromotionTotalPrice'] >= $ruleArray['full'][$ruleLength - 1]) {
         $rulePercent = max(0, $ruleArray['discount'][$ruleLength - 1]);
         $rulePercent = min($rulePercent, 100);
         $discount_price = ecmath::number_multiple(array($params['forPromotionTotalPrice'], 1 - $rulePercent / 100));
     } elseif ($params['forPromotionTotalPrice'] < $ruleArray['full']['0']) {
         $discount_price = 0;
     } else {
         for ($i = 0; $i < $ruleLength - 1; $i++) {
             if ($params['forPromotionTotalPrice'] >= $ruleArray['full'][$i] && $params['forPromotionTotalPrice'] < $ruleArray['full'][$i + 1]) {
                 $rulePercent = max(0, $ruleArray['discount'][$i]);
                 $rulePercent = min($rulePercent, 100);
                 $discount_price = ecmath::number_multiple(array($params['forPromotionTotalPrice'], 1 - $rulePercent / 100));
                 break;
             }
         }
     }
     if ($discount_price < 0) {
         $discount_price = 0;
     }
     return $discount_price;
 }
Beispiel #2
0
 /**
  * 生成订单总计详细
  * @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;
 }
Beispiel #3
0
 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;
     }
 }
Beispiel #4
0
 /**
  * @brief 加载每个店铺的商品数据信息
  *
  * @param array $shopCartData 店铺中加入购物车数据的
  * @param array $itemsData 加入购物车的基本商品数据集合
  * @param array $skusData 加入购物车的基本SKU数据集合
  *
  * @return array
  */
 private function __preShopCartInfo($shopCartData, $itemsData, $skusData, $needInvalid, $platform)
 {
     //现在只有普通商品购买流程,因此临时将商品结构写到此
     //如果有其他商品购买类型,则到各类型中进行商品获取
     foreach ($shopCartData as $row) {
         $k = $row['cart_id'];
         $itemId = $row['item_id'];
         $skuId = $row['sku_id'];
         $shopObjectData[$k]['cart_id'] = $row['cart_id'];
         $shopObjectData[$k]['item_id'] = $row['item_id'];
         $shopObjectData[$k]['selected_promotion'] = $row['selected_promotion'];
         $shopObjectData[$k]['sku_id'] = $row['sku_id'];
         $shopObjectData[$k]['cat_id'] = $itemsData[$itemId]['cat_id'];
         $shopObjectData[$k]['sub_stock'] = $itemsData[$itemId]['sub_stock'];
         $shopObjectData[$k]['spec_info'] = $skusData[$skuId]['spec_info'];
         $shopObjectData[$k]['bn'] = $skusData[$skuId]['bn'];
         //可售库存
         $shopObjectData[$k]['store'] = $skusData[$skuId]['realStore'];
         $shopObjectData[$k]['status'] = $itemsData[$itemId]['approve_status'];
         // 活动,剩余购买数量,如果剩余
         $restActivityNum = $this->restBuyNum($row['item_id'], $this->userId);
         if ($restActivityNum['ifactivity']) {
             if ($row['quantity'] >= $restActivityNum['restActivityNum']) {
                 $row['quantity'] = $restActivityNum['restActivityNum'] > 0 ? $restActivityNum['restActivityNum'] : 0;
             }
         }
         $shopObjectData[$k]['quantity'] = $row['quantity'];
         //购买数量
         $shopObjectData[$k]['sku_id'] = $row['sku_id'];
         if ($itemsData[$row['item_id']] && $skusData[$row['sku_id']]) {
             $shopObjectData[$k]['title'] = $itemsData[$itemId]['title'];
             $shopObjectData[$k]['image_default_id'] = $itemsData[$itemId]['image_default_id'];
         } else {
             $shopObjectData[$k]['title'] = $row['title'];
             $shopObjectData[$k]['image_default_id'] = $row['image_default_id'];
         }
         $shopObjectData[$k]['weight'] = $this->objMath->number_multiple(array($skusData[$skuId]['weight'], $row['quantity']));
         $activityDetail = $this->getItemActivityInfo($row['item_id'], $platform);
         if ($activityDetail['activity_price'] > 0) {
             $shopObjectData[$k]['price']['price'] = $activityDetail['activity_price'];
             //购买促销后单价
             $shopObjectData[$k]['price']['total_price'] = $this->objMath->number_multiple(array($activityDetail['activity_price'], $row['quantity']));
             //购买此SKU总价格
             $oldTotalPrice = $this->objMath->number_multiple(array($skusData[$skuId]['price'], $row['quantity']));
             //购买此SKU总价格
             $shopObjectData[$k]['price']['discount_price'] = ecmath::number_minus(array($oldTotalPrice, $shopObjectData[$k]['price']['total_price']));
             $shopObjectData[$k]['activityDetail'] = $activityDetail;
             $shopObjectData[$k]['promotion_type'] = 'activity';
             //活动类型(针对单品),
         } else {
             $shopObjectData[$k]['price']['price'] = $skusData[$skuId]['price'];
             //购买促销前单价
             $shopObjectData[$k]['price']['total_price'] = $this->objMath->number_multiple(array($skusData[$skuId]['price'], $row['quantity']));
             //购买此SKU总价格
         }
         $shopObjectData[$k]['valid'] = $this->__checkItemValid($itemsData[$itemId], $skusData[$row['sku_id']]);
         //是否为有效数据
         // 如果可购买数量小于等于0(一般是活动限购会导致此情况),则商品失效
         if ($shopObjectData[$k]['quantity'] <= 0) {
             $shopObjectData[$k]['valid'] = false;
         }
         if ($shopObjectData[$k]['valid']) {
             $shopObjectData[$k]['is_checked'] = $row['is_checked'];
         } else {
             $shopObjectData[$k]['is_checked'] = 0;
         }
         // 获取商品关联的促销信息
         $shopObjectData[$k]['promotion_ids'] = $itemsData[$itemId]['promotion_ids'];
         $shopObjectData[$k]['promotions'] = $this->getItemPromotionInfo($row['item_id'], $platform);
         if (!$needInvalid && (!$shopObjectData[$k]['valid'] || !$row['is_checked'])) {
             unset($shopObjectData[$k]);
         }
     }
     return $shopObjectData;
 }
Beispiel #5
0
 public function updateCart()
 {
     $mode = input::get('mode');
     $obj_type = input::get('obj_type', 'item');
     $postCartId = input::get('cart_id');
     $postCartNum = input::get('cart_num');
     $postPromotionId = input::get('promotionid');
     $params = array();
     foreach ($postCartId as $cartId => $v) {
         $data['mode'] = $mode;
         $data['obj_type'] = $obj_type;
         $data['cart_id'] = intval($cartId);
         $data['totalQuantity'] = intval($postCartNum[$cartId]);
         $data['selected_promotion'] = intval($postPromotionId[$cartId]);
         $data['user_id'] = userAuth::id();
         if ($v == '1') {
             $data['is_checked'] = '1';
         }
         if ($v == '0') {
             $data['is_checked'] = '0';
         }
         $params[] = $data;
     }
     try {
         foreach ($params as $updateParams) {
             $data = app::get('topc')->rpcCall('trade.cart.update', $updateParams);
             if ($data === false) {
                 $msg = app::get('topc')->_('更新失败');
                 return $this->splash('error', null, $msg, true);
             }
         }
     } catch (Exception $e) {
         $msg = $e->getMessage();
         return $this->splash('error', null, $msg, true);
     }
     $cartData = app::get('topc')->rpcCall('trade.cart.getCartInfo', array('platform' => 'pc', 'user_id' => userAuth::id()), 'buyer');
     $pagedata['aCart'] = $cartData['resultCartData'];
     // 临时统计购物车页总价数量等信息
     $totalWeight = 0;
     $totalNumber = 0;
     $totalPrice = 0;
     $totalDiscount = 0;
     foreach ($cartData['resultCartData'] as $v) {
         $totalWeight += $v['cartCount']['total_weight'];
         $totalNumber += $v['cartCount']['itemnum'];
         $totalPrice += $v['cartCount']['total_fee'];
         $totalDiscount += $v['cartCount']['total_discount'];
     }
     $totalCart['totalWeight'] = $totalWeight;
     $totalCart['number'] = $totalNumber;
     $totalCart['totalPrice'] = $totalPrice;
     $totalCart['totalAfterDiscount'] = ecmath::number_minus(array($totalPrice, $totalDiscount));
     $totalCart['totalDiscount'] = $totalDiscount;
     $pagedata['totalCart'] = $totalCart;
     $pagedata['defaultImageId'] = app::get('image')->getConf('image.set');
     foreach (input::get('cart_shop') as $shopId => $cartShopChecked) {
         $pagedata['selectShop'][$shopId] = $cartShopChecked == 'on' ? true : false;
     }
     $pagedata['selectAll'] = input::get('cart_all') == 'on' ? true : false;
     $msg = view::make('topc/cart/cart_main.html', $pagedata)->render();
     return $this->splash('success', null, $msg, true);
 }
Beispiel #6
0
 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;
 }