浏览代码

重构购买第一步

stanley-king 8 年之前
父节点
当前提交
f23499faf6
共有 5 个文件被更改,包括 250 次插入5 次删除
  1. 3 1
      data/logic/buy.logic.php
  2. 3 2
      data/logic/payment.logic.php
  3. 203 0
      helper/buy_first.php
  4. 35 0
      mobile/control/member_buy.php
  5. 6 2
      test/activity_helperTest.php

+ 3 - 1
data/logic/buy.logic.php

@@ -190,10 +190,12 @@ class buyLogic {
             $result['deny_edit_payment'] = true;
         }
 
+        $vat_deny = false;
         //发票 :只有所有商品都支持增值税发票才提供增值税发票
         foreach ($goods_list as $goods) {
         	if (!intval($goods['goods_vat'])) {
-        	    $vat_deny = true;break;
+        	    $vat_deny = true;
+                break;
         	}
         }
         //不提供增值税发票时抛出true(模板使用)

+ 3 - 2
data/logic/payment.logic.php

@@ -116,7 +116,8 @@ class paymentLogic
 
         $used_pred = intval(0);
         $can_used = 0;
-        foreach ($order_list as $order_info) {
+        foreach ($order_list as $order_info)
+        {
             // 计算运费+订单总额
             $cur_order_amount = intval(floatval($order_info['order_amount']) * 100 + 0.5);
             $cur_pd_amount = intval(floatval($order_info['pd_amount']) * 100 + 0.5);
@@ -124,7 +125,7 @@ class paymentLogic
 
             $order_pd_amount = $pred_helper->calc_pred($cur_order_amount, $pd_amount, $cur_pd_amount, $no_cash);
             $pd_amount -= $order_pd_amount;
-            $can_used += $order_pd_amount;
+            $can_used  += $order_pd_amount;
         }
 
         $used_pred = floatval($used_pred) / 100;

+ 203 - 0
helper/buy_first.php

@@ -0,0 +1,203 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/9/19
+ * Time: 下午6:48
+ */
+
+require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
+
+class buy_first
+{
+    private $mLogicOut;
+    public function __construct($logic_out)
+    {
+        $this->mLogicOut = $logic_out;
+    }
+    //商品金额相关信息
+    private function payinfo()
+    {
+        $result = [];
+
+        //商品总价,红包可抵扣,满减金额
+        $goods_amount = 0.00;
+        $store_goods_total = $this->mLogicOut['store_goods_total'];
+        foreach ($store_goods_total as $store_id => $value) {
+            $goods_amount += doubleval($value);
+        }
+
+        $result['goods_amount'] = $goods_amount;
+
+        //满送
+        $full_discount = 0.00;
+        $full_desc = '';
+        $store_mansong_rule_list = $this->mLogicOut['store_mansong_rule_list'];
+        foreach ($store_mansong_rule_list as $store_id => $value) {
+            $full_discount += doubleval($value['discount']);
+            $full_desc = $value['mansong_name'];
+        }
+        $result['full_discount'] = $full_discount;
+        $result['full_desc'] = $full_desc;
+        $result['full_goods'] = $this->full_goods();
+
+        //运费
+        $result['freight'] = $this->freight();
+        $result['freight_hash'] = $this->mLogicOut['freight_list'];
+
+        //红包信息
+        $result['total_pred'] = doubleval($this->mLogicOut['available_predeposit']);
+        $result['available_pred']  = $this->available_pred($goods_amount);
+        $result['usable_pred'] = true;
+
+        $result['vat_deny'] = $this->mLogicOut['vat_deny'];
+        $result['vat_hash'] = $this->mLogicOut['vat_hash'];
+
+        return $result;
+    }
+
+    private function full_goods()
+    {
+        $store_mansong_rule_list = $this->mLogicOut['store_mansong_rule_list'];
+        foreach ($store_mansong_rule_list as $store_id => $value) {
+            return intval($value['goods_id']);
+        }
+
+        return 0;
+    }
+
+    private function city_id()
+    {
+        $address_info = $this->mLogicOut['address_info'];
+        if(empty($address_info)) {
+            return false;
+        } else {
+            return intval($address_info['city_id']);
+        }
+    }
+    private function paytype()
+    {
+        //支付宝,微信,招商银行,各自的描述语
+        $types = [];
+        $types[] = array("payment" => "wxpay","desc" => "");
+        $types[] = array("payment" => "alipay","desc" => "");
+        $types[] = array("payment" => "cmbchina","desc" => "");
+        return $types;
+    }
+    //运费相关信息
+    private function freight()
+    {
+        $logic_buy_1 = Logic('buy_1');
+        $logic_buy = Logic("buy");
+        $freight_hash = $this->mLogicOut['freight_list'];
+        $freight_list = $logic_buy->buyDecrypt($freight_hash, $_SESSION['member_id']);
+        $city_id = $this->city_id();
+        $store_freight_total = $logic_buy_1->calcStoreFreight($freight_list,$city_id);
+
+        $freight = 0.00;
+        foreach ($store_freight_total as $key => $value) {
+            $freight += doubleval($value);
+        }
+        return $freight;
+    }
+    private function goods_ids()
+    {
+        $ids = [];
+        $sent_id = $this->full_goods();
+        if($sent_id > 0) {
+            $ids[] = $sent_id;
+        }
+
+        $carts = $this->goods_list();
+        foreach ($carts as $item)
+        {
+            if($item['bl_id'] > 0)
+            {
+                $bl_goods = activity_helper::bundling_goods($item['bl_id']);
+                if($bl_goods != false) {
+                    foreach ($bl_goods as $gid) {
+                        $ids[] = $gid;
+                    }
+                }
+            }
+            else
+            {
+                $ids[] = $item['goods_id'];
+            }
+        }
+
+        return $ids;
+    }
+    private function summary()
+    {
+        $goods_ids = $this->goods_ids();
+
+        $helper = new goods_helper();
+        $summaries = $helper->get_summary($goods_ids,$related_goods);
+        $summary_list = $summaries['summary'];
+        if(!empty($related_goods)) {
+            $related_summary = $helper->cart_summary($related_goods,$x);
+            $summary_list = array_merge($summary_list,$related_summary['summary']);
+        }
+
+        $ret['summary']  = $summary_list;
+        $ret['groupbuy'] = $summaries['groupbuy'];
+        $ret['limitime'] = $summaries['limitime'];
+        $ret['bundling'] = $summaries['bundling'];
+
+        return $ret;
+    }
+
+    private function address()
+    {
+        return $this->mLogicOut['address_info'];
+    }
+
+    private function goods_list()
+    {
+        //购物车中商品列表
+        $goods_list = [];
+        $store_cart_list = $this->mLogicOut['store_cart_list'];
+        foreach ($store_cart_list as $store_id => $carts)
+        {
+            foreach ($carts as $value) {
+                $item['goods_id'] = intval($value['goods_id']);
+                $item['goods_num'] = intval($value['goods_num']);
+                $item['bl_id'] = intval($value['bl_id']);
+
+                $goods_list[] = $item;
+            }
+        }
+
+        return $goods_list;
+    }
+
+    private function invoice()
+    {
+        //发票信息
+        return $this->mLogicOut['inv_info'];;
+    }
+    private function available_pred($goods_amount)
+    {
+        return intval($goods_amount * 0.3 * 100 + 0.5) / 100;
+    }
+
+    public function format()
+    {
+        $result = [];
+        $result['payinfo'] = $this->payinfo();
+        $result['paytype'] = $this->paytype();
+        $result['address'] = $this->address();
+        $result['invoice'] = $this->invoice();
+        $result['goods_list'] = $this->goods_list();
+
+        $summary = $this->summary();
+        $result['summary']  = $summary['summary'];
+        $result['groupbuy'] = $summary['groupbuy'];
+        $result['limitime'] = $summary['limitime'];
+        $result['bundling'] = $summary['bundling'];
+
+        return $result;
+    }
+}

+ 35 - 0
mobile/control/member_buy.php

@@ -13,6 +13,7 @@
 defined('InShopNC') or exit('Access Invalid!');
 
 require_once (BASE_ROOT_PATH . '/helper/predeposit_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/buy_first.php');
 
 class member_buyControl extends mbMemberControl
 {
@@ -20,6 +21,40 @@ class member_buyControl extends mbMemberControl
         parent::__construct();
     }
 
+    public function step_firstOp()
+    {
+        $cart_ids = explode(',', urldecode($_POST['cart_id']));
+        if(empty($cart_ids)) {
+            return self::outerr(errcode::ErrParamter);
+        }
+        else
+        {
+            $mod_cart = Model('cart');
+            $items = $mod_cart->listCart('db',array('cart_id' => array('in',$cart_ids)),false);
+            $id_num = [];
+            foreach ($items as $val)
+            {
+                $cart_id = $val['cart_id'];
+                $goods_num = $val['goods_num'];
+                $id_num[] = "{$cart_id}|{$goods_num}";
+            }
+        }
+
+        $logic_buy = logic('buy');
+        //得到购买数据
+        $result = $logic_buy->buyStep1($id_num, $_POST['ifcart'], $_SESSION['member_id'], $_SESSION['store_id']);
+        if (!$result['state']) {
+            return self::outerr(errcode::ErrOrder, $result['msg']);
+        } else {
+            $result = $result['data'];
+        }
+
+        $buy_helper = new buy_first($result);
+        $result = $buy_helper->format();
+
+        return self::outsuccess($result);
+    }
+
     /**
      * 购物车、直接购买第一步:选择收获地址和配置方式
      */

+ 6 - 2
test/activity_helperTest.php

@@ -22,14 +22,18 @@ class activity_helperTest extends PHPUnit_Framework_TestCase
 
     public function testGift()
     {
+        $time = strftime("%Y-%m-%d %H:%M:%S",1474266342);
+        $time = strftime("%Y-%m-%d %H:%M:%S",1474268695);
+        $time = strftime("%Y-%m-%d %H:%M:%S",1474268698);
+
         $helper = new goods_helper();
-        $helper->get_summary(array(4181),$related_goods);
+        //$helper->get_summary(array(4181),$related_goods);
     }
 
     public function testBundling()
     {
         $helper = new goods_helper();
-        $ret = $helper->get_summary(array(2),$related_goods);
+        //$ret = $helper->get_summary(array(2),$related_goods);
     }
 
     public function testSpu()