Your Name 2 年 前
コミット
63e7aedfff
1 ファイル変更36 行追加20 行削除
  1. 36 20
      tool/stats/lib/Manage.php

+ 36 - 20
tool/stats/lib/Manage.php

@@ -93,6 +93,7 @@ Class Manage
 		}
 		$where['state'] = 1;
 		$data = Dever::db('shop/sell_order')->getExcel($where);
+		// print_R($data);die;
 		$header = array('门店类型', '门店编号', '门店名称', '订单号', '商品编码', '存货编码', '商品名称', '规格型号', '税率', '商品单价', '购买数量', '商品合计金额', '代理优惠金额', '商品实付金额', '礼品卡金额', '钱包金额','商品支付金额', '礼品卡名称', '礼品卡卡号', '代理商注册时间', '下单时间', '付款时间', '发货时间', '完成时间', '订单总数量', '订单总金额', '订单实付金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '订单状态', '退款状态', '退款时间', '退款金额','退卡金额','退现金金额', '收件人', '收件人手机', '收件人地址');
 
 		$body = array();
@@ -158,8 +159,8 @@ Class Manage
 		        $refund_cash = '';
 		        $ka = 0;
 	            $money = 0;
-	            
 				$goods = Dever::db('shop/sell_order_goods')->select(Array('order_id'=>$v['id']));
+				// print_R($goods);die;
 				foreach($goods as $k1 => $v1) {
 					$goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
 					if (isset($goods_info['sku'])) {
@@ -206,9 +207,7 @@ Class Manage
 	                    	}
 	                    	
 	                    }
-	                    
-	                    // print_R($ka);die;
-	                    
+	                    	                    
 	                    $refund_cdate = '';
 	                    if ($v['shop_type'] == 1) {
 	                    	$refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
@@ -242,33 +241,43 @@ Class Manage
 		            // print_R($goods);die;
 		            // print_R($goods_info);die;
 	                if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
+	                	$dj = $this->danjia($goods_info['goods']);
 	                	$heji = 0;
+	                	
 	                	$heji = $this->total($goods,$v1['num']);
-	                	// print_R($v);die;
-						foreach ($goods_info['goods'] as $key => $val) {
 
+						foreach ($goods_info['goods'] as $key => $val) {
 							$dnum = round($val['num']*$v1['num'],2);
+							// print_R($dnum);die;
+							$goods_price = round($val['price']/$dj*$v1['price']*$v1['num'],2);
+							$danjia = round($goods_price/$dnum,2);
+							
+
 							$bili = round($val['price']*$dnum /$heji,2);#比例
+							// print_R($)
+							// $goods_price = round($val['price']*$dnum*($v1['price']/$heji),2);
 							// print_R($bili);die;
 							$price_money = $val['price']*$dnum*$v['discount_cash'];#支付
 							
 							if ($v['card_code_cash'] && $v['card_code_cash']>0){
-								$card_price = round(($v['card_code_cash']/$v['oprice']*($val['price']*$dnum)),2);
+								$card_price = round(($v['card_code_cash']/$v['oprice']*$goods_price),2);
+								// round(($v['card_code_cash']/$v['oprice']*($val['price']*$dnum)),2);
 							} else {
 								$card_price = 0;
 							}
-							$wallet_price = round(($v['wallet_cash']/$v['oprice']*($val['price']*$dnum)),2);
+							$wallet_price = round(($v['wallet_cash']/$v['oprice']*$goods_price),2);
+							// round(($v['wallet_cash']/$v['oprice']*($val['price']*$dnum)),2);
 							$goodsfu = 0;
 							if ($v1['discount_id']<=0) {
 								$youhui = 0;
-								if ($card_price + $wallet_price >=$val['price']*$dnum){
+								if ($card_price + $wallet_price >=$goods_price){
 									$goodsfu = 0;
 								} elseif ($card_price + $wallet_price ==0) {
-									$goodsfu = round($val['price']*$dnum,2);
+									$goodsfu = $goods_price;
+									// round($val['price']*$dnum,2);
 								} else {
-									$goodsfu = round($val['price']*$dnum-($card_price + $wallet_price),2);
+									$goodsfu = round($goods_price-($card_price + $wallet_price),2);
 								}
-								// print_R($card_price);die;
 								
 							} else {
 								$act = Dever::db('act/discount')->find($v['discount_id']);
@@ -276,14 +285,14 @@ Class Manage
 									$act_num = $act['num']/10;
 								}
 								if ($card_price + $wallet_price == 0) {
-									$goodsfu = round($val['price']*$dnum*$act_num,2);
-									$youhui = round($val['price']*$dnum-$goodsfu);
-								} elseif ($card_price + $wallet_price >=$val['price']*$dnum) {
+									$goodsfu = round($goods_price*$act_num,2);
+									$youhui = round($goods_price-$goodsfu);
+								} elseif ($card_price + $wallet_price >=$goods_price) {
 									$goodsfu = 0;
-									$youhui = round($val['price']*$dnum-$goodsfu-($card_price + $wallet_price),2);
+									$youhui = round($goods_price-$goodsfu-($card_price + $wallet_price),2);
 								} else {
-									$goodsfu = round($val['price']*$dnum-($card_price + $wallet_price),2);
-									$youhui = round($val['price']*$dnum-$goodsfu,2);
+									$goodsfu = round($goods_price-($card_price + $wallet_price),2);
+									$youhui = round($goods_price-$goodsfu,2);
 								}
 								
 
@@ -335,9 +344,9 @@ Class Manage
 								$sku,
 								$goods_info['tax'],
 
-								round($val['price'],2),
+								$danjia,//round($val['price'],2),
 								$dnum,
-								round(($val['price']*$dnum),2),
+								$goods_price,//round(($val['price']*$dnum),2),
 								round($youhui,2),
 								$goodsfu,
 								$card_price,
@@ -483,6 +492,13 @@ Class Manage
 		$file = '商品销售相关数据';
         return Dever::excelExport($body, $header, $file);
 	}
+	public function danjia($goods) {
+		$price = 0;
+		foreach($goods as $k => $v) {
+			$price+=$v['price'];
+		}
+		return $price;
+	}
 	
 	public function total($goods,$num){
 		if ($goods) {