protected function orderStatistics($cal_id) { //参团人 $allPrice = 0; $PeopleCount = 0; //保险 $insuranceCount = 0; $insurancePrice = 0; //门票 $addPrice = 0; $addCount = 0; //房间 $roomPrice = 0; $roomCount = 0; //捐款 $dotadePrice = 0; $dotadeCount = 0; $allArr = Order::model()->findAll(array( 'select'=>'id,aduit,child,daynumber,aduit_price,chilend_price,donate', 'condition'=>"cal_id=$cal_id and status=1" )); //单个订单总价格 foreach($allArr as $arr){ //基础价格 $allPrice += ($arr->aduit *$arr->aduit_price) + ($arr->child * $arr->chilend_price); $PeopleCount += ($arr->aduit) + ($arr->child); //捐款 if($arr->donate != 0){ $dotadePrice += $arr->donate; $dotadeCount += 1; } //保险 $insuranceModel = OrderInsurance::model()->find(array('select'=>'price','condition'=>"oid=$arr->id")); if($insuranceModel){ $insuranceCount += ($arr->aduit) + ($arr->child); $insurancePrice += ($arr->aduit + $arr->child) * $insuranceModel->price * $arr->daynumber; } //门票 $addModel = OrderAdditional::model()->findAll(array('select'=>'num,price','condition'=>"oid=$arr->id")); if($addModel){ foreach($addModel as $add){ $addCount += $add->num; $addPrice += $add->price * $add->num; } } //房间 $rooModel = OrderRoom::model()->findAll(array('select'=>'price','condition'=>"oid=$arr->id")); if($rooModel){ $roomCount += count($rooModel); foreach($rooModel as $roo){ $roomPrice += $roo->price; } } } return array($allPrice,$PeopleCount,$insurancePrice,$insuranceCount,$addPrice,$addCount,$roomPrice,$roomCount,$dotadePrice,$dotadeCount); }
public function actionPrintAdd($cid) { $cal_id = intval($cid); $arr = $this->orderStatistics($cal_id); $orders = Order::model()->findAll(array('select'=>'id,cid,trackcode','condition'=>"cal_id=$cal_id and status=1")); $tempArr[] = array('ID','订单ID','订单号','联系人','景点','门票数','门票单价','总价'); foreach($orders as $order){ $addModel = OrderAdditional::model()->findAll(array('condition'=>"oid=$order->id")); foreach($addModel as $add){ $tempArr[] = array($add->id,$add->oid,$order->trackcode,$this->getContorById($order->cid),$add->name,$add->num,$add->price,$add->num * $add->price); } } $rand = date('Y-m-d',time()).mt_rand(0,999); Yii::import('application.extensions.phpexcel.JPhpExcel'); $xls = new JPhpExcel('UTF-8', false, 'ordersheet'); $xls->addArray($tempArr); $xls->generateXML($rand."_AdditionalPrint"); exit; }
protected function addsTotalPrice($oid) { $totalPrice = 0; $arr = OrderAdditional::model()->findAll(array( 'select'=>'num,price', 'condition'=>"oid=$oid" )); if(!empty($arr)){ foreach($arr as $model){ $totalPrice += ($model->price)*($model->num); } } return $totalPrice; }
public function getTotalPriceFormDb($oid) { // 参团人基础价格 + 房间价格 + 附加项目(门票) + 保险 + 捐赠 //基础价格 $orderModel = Order::model()->findByPk($oid); $basePrice = 0; //保险价格 $insruancePrice = 0; //捐赠价格 $donatePrice = 0; //附加项目总价 $addsPrice = 0; //房间价格 $roomPrice = 0; if($orderModel!==null){ $basePrice = ($orderModel->aduit * $orderModel->aduit_price) + ($orderModel->child * $orderModel->chilend_price); //捐赠价格 $donatePrice = $orderModel->donate; //保险价格 $insruanceModel = OrderInsurance::model()->find(array('select'=>'price','condition'=>"oid=$oid")); if($insruanceModel!==null){ $insruancePrice = ($orderModel->aduit + $orderModel->child) * $insruanceModel->price * $orderModel->daynumber; } //房间价格 $roomModel = OrderRoom::model()->findAll(array('select'=>'price','condition'=>"oid=$oid")); if(!empty($roomModel)){ foreach($roomModel as $m){ $roomPrice += $m->price; } } //附加项目总价 $addsModel = OrderAdditional::model()->findAll(array('select'=>'num,price','condition'=>"oid=$oid")); foreach($addsModel as $adds){ $addsPrice += $adds->num * $adds->price; } } return $basePrice + $insruancePrice + $donatePrice + $addsPrice + $roomPrice; }