Ver código fonte

Merge branch 'master' of ssh://git.dever.cc:10022/dever-product/churen

rabin 2 anos atrás
pai
commit
249602b0ca

+ 1 - 1
app/shop/database/info.php

@@ -887,7 +887,7 @@ return array
             ),
             'type' => 'all',
             'order' => array('reorder' => 'desc', 'id' => 'desc'),
-            'col' => 'id,id as value, name',
+            'col' => 'id,id as value, name,agent_mid',
         ),
 
         'getAllByType' => array

+ 7 - 5
service/bill/database/shop_stat.php

@@ -38,11 +38,13 @@ if ($table == 'shop_stat') {
     $button['一键生成归店信息'] = array('oper', 'bill/?l=lib/Cron.shop_stat&day=' . $month, '确认生成归店统计信息吗?');
 
     $button['重新生成归店信息'] = array('oper', 'bill/?l=lib/Cron.shop_stat&day=' . $month, '确认生成归店统计信息吗?');
-// print_R($month);die;
-    $button['对账确认'] = array('oper', 'bill/?l=lib/cron.shopYes_commit&month=' . $month, '确定已完成对账?');
-
-    $button['确认发放'] = array('oper', 'bill/?l=lib/cron.areaCash_commit&month=' . $month, '确认发放资金到代理商账户吗?确认后无法手动恢复');
-
+    if (Dever::load('manage/auth')->checkFunc('bill.shop_stat', 'duizhang', '对账确认')) {
+        $button['对账确认'] = array('oper', 'bill/?l=lib/cron.shopYes_commit&month=' . $month, '确定已完成对账?');
+    }
+    
+    if (Dever::load('manage/auth')->checkFunc('bill.shop_stat', 'fafang', '确认发放')) {
+        $button['确认发放'] = array('oper', 'bill/?l=lib/cron.areaCash_commit&month=' . $month, '确认发放资金到代理商账户吗?确认后无法手动恢复');
+    }
 }
 $config = array
 (

+ 21 - 11
service/bill/lib/Cron.php

@@ -564,7 +564,7 @@ class Cron
                     $audit = '';
                 }
                 
-                // $manage['info'] = date('Y年m月', $month) . ' 可分润城市 ' . $log['city_num'] . ' 个 分润区县 ' . $log['county_num'] . ' 个 分润街道 ' . $log['town_num'] . ' 个(不含赠送区域) ' . $audit;
+                $manage['info'] = '代理商总数=创V数+代理商数量,创V数包含名额外创V数,创V数减去名额外创V就是名额内创V数,代理商数量包含创客数'. $audit;
 
             }
             
@@ -601,6 +601,17 @@ class Cron
         $start = Dever::maketime($start_time);
         $end = Dever::maketime($end_time);
         $shops = Dever::db('shop/info')->getguiAll(array('type'=>2));
+        if ($shops) {
+            $shop_data = array();
+            foreach ($shops as $k => $v) {
+                if ($v['agent_mid'] <1) {
+                    $shop_data[$v['id']] = $v['name'];
+                }
+            }
+            if ($shop_data) {
+                Dever::alert('以下门店没有绑定代理商:' . implode(',', $shop_data));
+            }
+        }
         foreach ($shops as $k => $v) {
             #业绩补贴:除了创V0.02,创V>=10个0.05,创V>=20个0.08
             // $subsidy = 0;
@@ -746,14 +757,12 @@ class Cron
                 $insert['dl_subsidy'] = 0;
                 $insert['v_subsidy'] = 0;
                 $res = Dever::db('bill/shop_stat')->find(array('month'=>$insert['month'],'shop_id'=>$v['id']));
-                // print_R($res);die;
                 if ($res) {
                     $insert['where_id'] = $res['id'];
                     Dever::db('bill/shop_stat')->update($insert);
                 } else {
                     Dever::db('bill/shop_stat')->insert($insert);
                 }
-                // echo dever::sql();
             }
             
         }
@@ -801,23 +810,24 @@ class Cron
                 foreach ($data as $k => $v) {
                     if ($v['shop_id']) {
                         $shop = Dever::db('shop/info')->find($v['shop_id']);
-                        if (isset($shop) && $shop && isset($shop['mobile']) && $shop['mobile']) {
-                            $member = Dever::db('agent/member')->find(array('mobile'=>$shop['mobile']));
+                        if (isset($shop) && $shop && isset($shop['agent_mid']) && $shop['agent_mid']) {
+                            $member = Dever::db('agent/member')->find($shop['agent_mid']);
                             $cash = $v['dl_subsidy'] + $v['v_subsidy'];
                             if ($member && $member['status'] == 2) {
                                 if ($v['dl_subsidy'] > 0) {
                                     $desc = $shop['name'].$date.'区域招商补贴';
                                     $state = Dever::load('bill/lib/cash')->up($member['id'], 13, $v['dl_subsidy'], $member['role'], $v['id'], $desc, 2, true);
-                                } elseif ($v['v_subsidy'] >0) {
+                                } 
+                                if ($v['v_subsidy'] >0) {
                                     $desc = $shop['name'].$date.'名额外创V补贴';
                                     $state = Dever::load('bill/lib/cash')->up($member['id'], 14, $v['v_subsidy'], $member['role'], $v['id'], $desc, 2, true);
                                 }
                                 if (isset($state) && $state) {
-                                    $where = array();
-                                    $where['where_id'] = $shop['id'];
-                                    $where['price'] = $shop['price'] + $cash;
-                                    $where['clear'] = true;
-                                    Dever::db('shop/info')->upCash($where);
+                                    // $where = array();
+                                    // $where['where_id'] = $shop['id'];
+                                    // $where['price'] = $shop['price'] + $cash;
+                                    // $where['clear'] = true;
+                                    // Dever::db('shop/info')->upCash($where);
                                     Dever::db('bill/shop_stat')->update(array('where_id' => $v['id'], 'cash_status' => 1));
                                 }
                             }

+ 257 - 223
tool/stats/lib/Manage.php

@@ -47,9 +47,6 @@ Class Manage
 	}
 	public function list_api()
 	{
-		$header = array('门店类型', '门店编号', '门店名称', '订单号', '商品编码', '存货编码', '商品名称', '规格型号', '税率', '商品单价', '购买数量', '商品合计金额', '代理优惠金额', '商品实付金额', '礼品卡金额', '钱包金额','商品支付金额', '礼品卡名称', '礼品卡卡号', '代理商注册时间', '下单时间', '付款时间', '发货时间', '完成时间', '订单总数量', '订单总金额', '订单实付金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '订单状态', '退款状态', '退款时间', '退款金额','退卡金额','退现金金额', '收件人', '收件人手机', '收件人地址');
-
-		$body = array();
 		$status = Dever::db('shop/sell_order')->config['status_manage'];
 		$start = Dever::input('start');
 		$end = Dever::input('end');
@@ -96,116 +93,122 @@ Class Manage
 		}
 		$where['state'] = 1;
 		$data = Dever::db('shop/sell_order')->getExcel($where);
-		// print_R($data);die;
+		$header = array('门店类型', '门店编号', '门店名称', '订单号', '商品编码', '存货编码', '商品名称', '规格型号', '税率', '商品单价', '购买数量', '商品合计金额', '代理优惠金额', '商品实付金额', '礼品卡金额', '钱包金额','商品支付金额', '礼品卡名称', '礼品卡卡号', '代理商注册时间', '下单时间', '付款时间', '发货时间', '完成时间', '订单总数量', '订单总金额', '订单实付金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '订单状态', '退款状态', '退款时间', '退款金额','退卡金额','退现金金额', '收件人', '收件人手机', '收件人地址');
+
+		$body = array();
 		if ($data) {
 			foreach ($data as $k => $v) {
-				$v['card'] = '';
-				$v['card_code'] = '';
-		        if ($v['card_code_id']) {
-		            $code = Dever::db('card/code')->find($v['card_code_id']);
-		            if ($code) {
-		                $card_info = Dever::db('card/info')->find($code['card_id']);
-		                if ($card_info) {
-		                    if (!$code['total_cash']) {
-		                        $code['total_cash'] = $card_info['value'];
-		                    }
-		                    $v['card'] = $card_info['name'];
-		                    $v['card_code'] = $code['card'];
-		                }
-		            }
-		        }
+				$shop_type = '';
 				if ($v['shop_type'] == 1) {
-					$v['shop_type_name'] = '体验店';
+					$shop_type = '体验店';
 				} elseif ($v['shop_type'] == 2) {
-					$v['shop_type_name'] = '平台商城';
+					$shop_type = '平台商城';
 				}
-				$shop = Dever::db('shop/info')->find(Array('id'=>$v['shop_id']));
-				if (isset($shop) && $shop) {
-					$data[$k]['shop_sid'] = $shop['sid'];
-					$data[$k]['shop_name'] = $shop['name'];
+				$shop = Dever::db('shop/info')->find($v['shop_id']);
+				$sid = '';
+				$shop_name = '';
+				if ($shop) {
+					if (isset($shop['sid']) && $shop['sid'] ) {
+						$sid = $shop['sid'];
+					}
+					if (isset($shop['name']) && $shop['name']) {
+						$shop_name = $shop['name'];
+					}
 				}
-				$zhuce = '';
-				$address_contact = '';
-				$address_mobile = '';
-				$address_info = '';
-				if ($v['address_id'] > 0) {
-        			$address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
-        			if($address) {
-        				$address_contact = $address['contact'];
-        				$address_mobile = $address['mobile'];
-        				$address_info = $address['address_info'];
-        				$member = Dever::db('agent/member')->find(array('mobile'=>$address['mobile']));
-        				if ($member) {
-        					$zhuce = date('Y-m-d H:i',$member['cdate']);
-        				}
-        			}
-        		}
-        		$ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
-	            $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
+				$v['card'] = '';
+				if ($v['card_code_id']) {
+			            $code = Dever::db('card/code')->find($v['card_code_id']);
+			            if ($code) {
+			                $card_info = Dever::db('card/info')->find($code['card_id']);
+			                if ($card_info) {
+			                    if (!$code['total_cash']) {
+			                        $code['total_cash'] = $card_info['value'];
+			                    }
+			                    $v['card'] = $card_info['name'];
+			                    $v['card_code'] = $code['card'];
+			                }
+			            }
+			        }
+			        $zhuce = '';
+					$address_contact = '';
+					$address_mobile = '';
+					$address_info = '';
+					if ($v['address_id'] > 0) {
+	        			$address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
+	        			if($address) {
+	        				$address_contact = $address['contact'];
+	        				$address_mobile = $address['mobile'];
+	        				$address_info = $address['address_info'];
+	        				$member = Dever::db('agent/member')->find(array('mobile'=>$address['mobile']));
+	        				if ($member) {
+	        					$zhuce = date('Y-m-d H:i',$member['cdate']);
+	        				}
+	        			}
+	        		}
+				$ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
+				$cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
 	            $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
 	            $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
-				$goods = Dever::db('shop/sell_order_goods')->select(Array('order_id'=>$v['id']));
-				$fdate = '';
+	            $fdate = '-';
 				if ($v['fdate']) {
 					$fdate = date('Y-m-d H:i',$v['fdate']);
 				}
-				// print_R($v);die;
-				foreach ($goods as $k1 => $v1) {
+				$refund_status = '';
+		        $refund_cdate = '';
+		        $refund_cash = '';
+		        $ka = 0;
+	            $money = 0;
+	            
+				$goods = Dever::db('shop/sell_order_goods')->select(Array('order_id'=>$v['id']));
+				foreach($goods as $k1 => $v1) {
 					$goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
-					// print_R($goods_info);die;
 					if (isset($goods_info['sku'])) {
 	                    $sku = $goods_info['sku']['string'];
 	                } else {
 	                    $sku = '';
 	                }
-	                $goods_price = $v1['price']*$v1['num'];
-	                #代理优惠金额
-	                $dl_discount_cash = round($v1['discount_cash'],2);
-	                // $discount_cash = round($v['discount_cash'],2);
-	                #商品实付金额
-	                $price = round(($goods_price-$dl_discount_cash),2);
-	                // round(($goods_price/$v['oprice']*$v['price']),2);
-	                //round(($v['price']/$goods_price),2);
-	                #礼品卡金额
-	                $card_code_cash = round($v['card_code_cash'],2);
-	                #钱包金额
-	                $wallet_cash = round($v['wallet_cash'],2);
-	                #商品支付金额
-	                #
-	                
 	                if ($k1 == 0) {
 	                	$total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
 	                } else {
 	                	$total_cash = 0;
 	                }
-	                $ka = 0;
-	                $money = 0;
-	                 if ($v['status'] == 8 || $v['status'] == 6) {
-	                    $num = $v1['num'];
-	                    $refund_cash = $v1['price']*$v1['num'];
+	                if ($v['status'] == 8 || $v['status'] == 6) { 
+	                	$refund_status = '已退款';
+		            	$refund_cash = $v1['price']*$v1['num'];
 	                    if ($v['status'] == 8) {
 	                    	if ($v['refund_cash'] && $v['refund_cash']>0) {
-		                    	$money = $v['refund_cash'];
+		                    	$money = $v['refund_cash']+$v['wallet_cash'];
 		                    }
 		                    if ($v['card_code_cash'] && $v['card_code_cash'] >0) {
 		                    	$ka = $v['card_code_cash'];
 		                    }
+		                    if ($k1 == 0) {
+		                    	$ka = $ka;
+		                    	$money = $money;
+		                    } else {
+		                    	$ka = 0;
+		                    	$money = 0;
+		                    }
 	                    } elseif ($v['status'] == 6) {
-	                    	if ($v['card_code_id'] && $v['card_code_id'] >0) {
-	                    		$ka = $v['refund_cash'];
+	                    	if ($v1['status'] == 3) {
+	                    		if ($v['card_code_id'] && $v['card_code_id'] >0) {
+	                    			
+		                    		$ka = $v['refund_cash'];
+		                    	} else {
+		                    		$money = $v['refund_cash'];
+		                    	}
+		                    	$refund_status = '已退款';
 	                    	} else {
-	                    		$money = $v['refund_cash'];
+	                    		$refund_status = '正常';
+	                    		$refund_cash = 0;
+	                    		$ka = 0;
+	                    		$money = 0;
 	                    	}
+	                    	
 	                    }
-	                    if ($k1 == 0) {
-	                    	$ka = $ka;
-	                    	$money = $money;
-	                    } else {
-	                    	$ka = 0;
-	                    	$money = 0;
-	                    }
 	                    
-	                    $refund_status = '已退款';
+	                    // print_R($ka);die;
+	                    
 	                    $refund_cdate = '';
 	                    if ($v['shop_type'] == 1) {
 	                    	$refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
@@ -213,32 +216,16 @@ Class Manage
 								$refund_cdate = date('Y-m-d H:i',$refund['cdate']);
 							}
 	                    }
-	                    
-	                } else {
-	                	#有退款的情况
-		                if ($v['refund_status'] == 3 && $v1['status'] == 3) {
+		            } else {
+		            	if ($v['refund_status'] == 3 && $v1['status'] == 3) {
+		            		$refund_cash = $v1['num']*$v1['price'];
+		                	if ($v['card_code_id'] && $v['card_code_id'] >0) {
+	                    		$ka = $v['refund_cash'];
+	                    	} else {
+	                    		$money = $v['refund_cash'];
+	                    	}
+		                    	// $refund_status = '已退款';
 		                	$refund_status = '有退款';
-		                	$refund_cash = $v1['num']*$v1['price'];
-		                	if ($refund_cash)
-		                	if ($v['refund_cash']>$refund_cash) {
-		                		if ($k1 == 0) {
-			                    	if ($v['card_code_cash'] && $v['card_code_cash'] >0) {
-				                    	$ka = $v['refund_cash'];
-				                    } else {
-				                    	$money = $v['refund_cash'];
-				                    }
-			                    }else {
-			                    	$ka = 0;
-			                    	$money = 0;
-			                    }
-		                	} else {
-		                		if ($v['card_code_id'] && $v['card_code_id'] >0) {
-				                    	$ka = $v['refund_cash'];
-				                    } else {
-				                    	$money = $v['refund_cash'];
-				                    }
-		                	}
-		                    
 		                    $refund_cdate = '';
 		                    if ($v['shop_type'] == 1) {
 		                    	$refund = Dever::db('shop/sell_order_refund')->find(array('order_id'=>$v['id']));
@@ -246,156 +233,203 @@ Class Manage
 									$refund_cdate = date('Y-m-d H:i',$refund['cdate']);
 								}
 		                    }
-		                } else {
-		                	$refund_cdate = '';
-		                    $num = '0';
+		            	} else {
+		            		$refund_cdate = '';
 		                    $refund_cash = '0';
 		                    $refund_status = '未退款';
-		                }
-	                }
-	                
-	                // if ($v['status'] >=7) {
-	                // 	$v['price'] = 0;
-	                // }
-	                
-	                if ($k1 == 0) {
-	                    $v['num'] = $v['num'];
-	                    $zhifu = round($v['price'],2);
-	                    $coupon_cash = round($v['coupon_cash'],2);#优惠券金额
-	                    $card_code_cash = round($v['card_code_cash'],2);#礼品卡金额
-						$wallet_cash = round($v['wallet_cash'],2);#钱包金额
-						$discount_cash = round($v['discount_cash'],2);
-	                    
-	                } else {
-	                    $v['num'] = 0;
-	                    
-	                    $zhifu = 0;
-	                    $v['wallet_cash'] = 0;
-	                    $coupon_cash = 0;
-	                    $card_code_cash = 0;
-	                    $wallet_cash = 0;
-	                    $discount_cash = 0;
-	                    
-	                }
-	                // print_R($v['price']);die;
-	                $d = array
-                    (
-                        $v['shop_type_name'],
-						$data[$k]['shop_sid'],
-						$data[$k]['shop_name'],
-						$v['order_num'],
-						$goods_info['code'] . "\t",
-						$goods_info['cunhuo_code'] . "\t",
-                    	$goods_info['name'],
-						$sku,
-						$goods_info['tax'],
-
-						round($v1['price'], 2),//商品单价
-						round($v1['num'],2),//商品数量
-						round($v1['price']*$v1['num'], 2),//商品合计金额
-						$dl_discount_cash,//代理商优惠金额
-						$price,//商品实付金额
-						$card_code_cash,//礼品卡
-						$wallet_cash, //钱包
-						$zhifu,//商品支付
-						$v['card'],
-						$v['card_code']."\t",
-						$zhuce,
-						$cdate,
-						$paydate,
-						$operdate,
-						$fdate,
-						$v['num'],//订单总量
-						sprintf('%01.2f',$total_cash),//订单总金额
-	                    $zhifu,//订单实付
-	                    $card_code_cash,//礼品卡
-	                    $wallet_cash,//钱包
-	                    $coupon_cash,//优惠券
-	                    $discount_cash,//代理优惠
-	                    $status[$v['status']],
-	                    $refund_status,
-	                    $refund_cdate,
-	                    round($refund_cash, 2),
-	                    round($ka,2),
-	                    round($money,2),
-	                    $address_contact,
-	                    $address_mobile,
-	                    $address_info,
-                    );
-					
-					// $body[] = $d;
-					if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
-                    
-	                    foreach ($goods_info['goods'] as $k2 => $v2) {
+		            	}
+		            }
+		            // print_R($goods);die;
+		            // print_R($goods_info);
+	                if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
+	                	$heji = 0;
+	                	$heji = $this->total($goods);
+	                	// print_R($heji);die;
+						foreach ($goods_info['goods'] as $key => $val) {
+							// $val['price']-($val['price']*)
+							$youhui = ($val['price']*($val['num']+$v1['num'])-($val['price']*($val['num']+$v1['num'])/$heji)*$v['price'])*$v1['num'];
+							$card_price = ($v['card_code_cash']/$heji*($val['price']*($val['num']+$v1['num'])))*$v1['num'];
+							$wallet_price = ($v['wallet_cash']/$heji*($val['price']*($val['num']+$v1['num'])))*$v1['num'];
+							$goodsfu = $val['price']*($val['num']+$v1['num'])-$youhui-$card_price-$wallet_price;
+							if ($key == 0) {
+								$price = round($v1['price']*$v1['num']-$v1['discount_cash'],2);
+								$shifu = round($v['price'],2);//实付金额
+								$order_num = $v1['num'];#订单总数量
+								$oprice = round($v1['price']*$v1['num'],2);#订单总金额
+								$coupon_cash = round($v1['coupon_cash'],2);
+								$discount_cash = round($v1['discount_cash'],2);
+								$card_code_cash = round($v['card_code_cash'],2);
+								$wallet_cash = round($v['wallet_cash'],2);
+							} else {
+								$price = 0;
+								$shifu = 0;
+								$order_num = 0;
+								$oprice = 0;#订单总金额
+								$coupon_cash = 0;
+								$discount_cash = 0;
+								$card_code_cash = 0;
+								$wallet_cash = 0;
+							}
+							if($v1['num']>1)  {
+								$dnum = round($val['num']+$v1['num'],2);
+							} else {
+								$dnum = round($val['num'],2);
+							}
 
-	                        if ($v2['code']) {
-	                            //$v2['code'] = '-' . $v2['code'];
-	                        }
-	                        $p = $v2['price'];
-	                        if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
-	                            $p = $v2['price']*$v2['num'];
-	                        }
-	                        $goods_price1 = 0;
-	                        
-	                        $d = array
+							$d = array
 							(
-								$v['shop_type_name'],
-								$data[$k]['shop_sid'],
-								$data[$k]['shop_name'],
+								$shop_type,
+								$sid,
+								$shop_name,
 								$v['order_num'],
-								$v2['code'] . "\t",
-								$goods_info['cunhuo_code'] . "\t",
-								$goods_info['name'],
+								$val['code']."\t",
+								$goods_info['cunhuo_code']."\t",
+								$val['name'].'('.$goods_info['name'].')',
 								$sku,
 								$goods_info['tax'],
 
-								round($goods_info['price'], 2),#单价
-								round($v1['num'],2),#数量
-								round(($goods_info['price']*$v1['num']),2),#商品合计金额
-								$dl_discount_cash,//代理商优惠金额
-								$price,#实付金额
-								$card_code_cash,#礼品卡金额
-								$wallet_cash,#钱包金额
-								$zhifu,#商品支付金额
+								round($val['price'],2),
+								$dnum,
+								round(($val['price']*($val['num']+$v1['num'])),2),
+								round($youhui,2),
+								$goodsfu,
+								$card_price,
+								$wallet_price,
+								$price,
+
 								$v['card'],
-								$v['card_code']."\t",
+								$v['card_code_card']."\t",
 								$zhuce,
 								$cdate,
 								$paydate,
 								$operdate,
 								$fdate,
-								$v['num'],
-								sprintf('%01.2f',$total_cash),
-			                    $zhifu,//订单实付
-			                    $card_code_cash,//礼品卡
-			                    $wallet_cash,//钱包
-			                    $coupon_cash,//优惠券
-			                    $discount_cash,//代理优惠
-			                    $status[$v['status']],
+
+								$order_num,
+								$oprice,
+								$price,
+								$card_code_cash,
+								$wallet_cash,
+								$coupon_cash,
+								$discount_cash,
+
+								$status[$v['status']],
 			                    $refund_status,
 			                    $refund_cdate,
+
 			                    round($refund_cash, 2),
 			                    round($ka,2),
 			                    round($money,2),
+
 			                    $address_contact,
 			                    $address_mobile,
 			                    $address_info,
 							);
+							$body[] = $d;
+						}
+					} else {
+						if ($k1 == 0) {
+							$discount_cash = round($v['discount_cash'],2);
+							$card_code_cash = round($v['card_code_cash'],2);
+							$wallet_cash = round($v['wallet_cash'],2);
+							$zhifu = $v['price'];
+							$total = $v['oprice']-($card_code_cash + $wallet_cash + $discount_cash+$zhifu);
+							$order_num = $v['num'];//订单总数量
+							$oprice = round($v['oprice'],2);#订单总金额
+							$coupon_cash = round($v['coupon_cash'],2);
+						} else {
+							$discount_cash = 0;
+							$card_code_cash = 0;
+							$wallet_cash = 0;
+							$total = 0;
+							$zhifu = 0;
+							$order_num = 0;
+							$oprice = 0;
+							$coupon_cash = 0;
+						}
+						// print_R($v1['price']*$v1['num']/$v['oprice']*$v['price']);die;
+						$dyouhui = round($v1['discount_cash'],2);
+						// ($v1['price']*$v1['num']/$v['oprice']*$v['price']);
+						// print_R($dyouhui);die;
+						$dcard_price = $v['card_code_cash']/$v['oprice']*($v1['price']*$v1['num']);
+						$dwallet_price = $v['wallet_cash']/$v['oprice']*($v1['price']*$v1['num']);
+						$dgoodsfu = $v1['price']*$v1['num']-$dyouhui-$dcard_price-$dwallet_price;
+						if ($dgoodsfu<0){
+							$dgoodsfu = 0;
+						}
+						$d = array
+						(
+							$shop_type,
+							$sid,
+							$shop_name,
+							$v['order_num'],
+							$goods_info['code']."\t",
+							$goods_info['cunhuo_code']."\t",
+							$goods_info['name'],
+							$sku,
+							$goods_info['tax'],
 
-	                        
-	                    }
-	                }
-	                $body[] = $d;
+							round($v1['price'],2),
+							round($v1['num'],2),
+							round(($v1['price']*$v1['num']),2),
+							round($dyouhui,2),
+							$dgoodsfu,
+							$dcard_price,
+							$dwallet_price,
+							$zhifu,
+
+							$v['card'],
+							$v['card_code_card']."\t",
+							$zhuce,
+							$cdate,
+							$paydate,
+							$operdate,
+							$fdate,
+
+							$order_num,
+							sprintf('%01.2f',$total_cash),
+							$zhifu,
+							$card_code_cash,
+							$wallet_cash,
+							$coupon_cash,//优惠券
+		                    $discount_cash,//代理优惠
+
+		                    $status[$v['status']],
+		                    $refund_status,
+		                    $refund_cdate,
+
+		                    round($refund_cash, 2),
+		                    round($ka,2),
+		                    round($money,2),
+
+		                    $address_contact,
+		                    $address_mobile,
+		                    $address_info,
+
+						);
+						$body[] = $d;
+
+					}					
 				}
 				
 			}
-			
+
 		}
 		if (!$body) {
 			Dever::alert('此时段没有数据,请重新选择条件');
 		}
 		$file = '商品销售相关数据';
-    	return Dever::excelExport($body, $header, $file);
+        return Dever::excelExport($body, $header, $file);
+	}
+	public function total($goods){
+		// print_R($goods);die;
+		if ($goods) {
+			$price = 0;
+			foreach ($goods as $k => $v) {
+				$price += $v['price'] * $v['num'];
+			}
+			return $price;
+		}
 	}
 	public function memberGoods_api()
 	{