public function actionShowDetail() { //$endmoth = strtotime(date('Y-m')); $ServiceID = Yii::app()->request->getParam('ServiceID'); $organID = Yii::app()->user->getOrganID(); //收益百分比 暂无 $discountRate = Settings::getValue("discountRate"); //$discountRate = 0.02; $record = RecommendRecord::model()->find("DealerID=:DealerID and ServiceID=:ServiceID", array(":DealerID" => $organID, ":ServiceID" => $ServiceID)); $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->addCondition('Status=9'); $startdate = date('Y-m', time()); $startdate = strtotime($startdate); $enddate = strtotime("-1 month", $startdate); $criteria->addBetweenCondition('ReceiptTime', $enddate, $startdate); //$criteria->addCondition("ReceiptTime<" . $endmoth); $criteria->addCondition("BuyerID=" . $ServiceID); if (empty($record)) { $criteria->addCondition("SellerID=" . $organID); } else { $criteria->addCondition("SellerID!=" . $organID); } $dataProvider = new CActiveDataProvider('Order', array('criteria' => $criteria, 'pagination' => array('pageSize' => '10'))); $data = $dataProvider->getData(); //无法传值到表单中 暂时用PayStatus字段保存收益 foreach ($data as $key => $value) { $data[$key]['PayStatus'] = round($data[$key]['RealPrice'] * $discountRate, 2); if ($data[$key]['SellerID'] == $organID) { $data[$key]['PayStatus'] = '-' . $data[$key]['PayStatus']; } } //var_dump($dataProvider);die; $this->render('showorderdetail', array('dataProvider' => $dataProvider)); }
/** * 计算经销商推荐收益 * 每个月1号执行一次, 或者每隔1个月执行一次 * @param unknown $args */ public function run($args) { Yii::app()->getComponent('log'); Yii::log(date('Y-m-d H:i:s') . " [RecommendIncome] start", 'info', 'command'); echo date('Y-m-d H:i:s') . " [RecommendIncome] start \n"; $beginmoth = strtotime('-1 month'); $year = date('Y', $beginmoth); $month = date('m', $beginmoth); $beginmoth = date('Y-m', $beginmoth); $beginmoth = strtotime($beginmoth); $endmoth = date('Y-m'); $endmoth = strtotime($endmoth); $Time = date('Y-m', time()); $Time = strtotime($Time); Yii::log('beginmoth:' . $beginmoth, 'info', 'command'); Yii::log('beginyear:' . $year, 'info', 'command'); Yii::log('beginmoth:' . $beginmoth, 'info', 'command'); Yii::log('endmoth:' . $endmoth, 'info', 'command'); Yii::log('time:' . $Time, 'info', 'command'); $discountRate = Settings::getValue("discountRate"); //获取推荐收益参数 $criteria = new CDbCriteria(); $criteria->select = 'userID'; $criteria->distinct = true; $criteria->order = 'userID desc'; $sql_find = 'select ID from jpd_organ where Identity=2'; $dealers = Yii::app()->jpdb->createcommand($sql_find)->queryAll(); if (!empty($dealers)) { foreach ($dealers as $deakey => $deaval) { $IncomeID = ''; $exit = RecommendIncome::model()->find('OrganID=:OrganID and Month=:Month and Year=:Year', array(':OrganID' => $deaval['ID'], ':Month' => $month, ':Year' => $year)); if ($exit) { $IncomeID = $exit->ID; } else { $model = new RecommendIncome(); $model->EffectTime = time(); $model->OrganID = $deaval['ID']; $model->IsAccount = 0; $model->Month = $month; $model->Year = $year; $model->save(); $IncomeID = Yii::app()->jpdb->getLastInsertID(); } $serviceID = ''; $lastmonthtotal = 0; $Record_all = RecommendRecord::model()->findAll('DealerID=:OrganID ', array(':OrganID' => $deaval['ID'])); if ($Record_all) { foreach ($Record_all as $app2) { if (!empty($app2)) { if ($app2->ServiceID) { $serviceID[] = $app2->ServiceID; $app4 = PapOrder::model()->findAll('BuyerID=:BuyerID and Status=:Status and SellerID!=:SellerID and ReceiptTime<:endmoth and ReceiptTime>=:beginmoth', array(':BuyerID' => $app2->ServiceID, ':Status' => 9, ':SellerID' => $deaval['ID'], ':endmoth' => $endmoth, ':beginmoth' => $beginmoth)); if (!empty($app4)) { $month1 = 0; foreach ($app4 as $ke => $valu) { $discountAmount = $valu['RealPrice'] * $discountRate; // $payAmount = is_float($discountAmount) ? substr_replace($discountAmount, '', strpos($discountAmount, '.') + 3) : $discountAmount . '.00'; $payAmount = round($discountAmount, 2); $month1 += $payAmount; $lastmonthtotal += $payAmount; } $detail = RecommendIncomeDetail::model()->find("OrganID=:OrganID and ServiceID=:ServiceID and incomeID=:incomeID", array(':OrganID' => $deaval['ID'], ":ServiceID" => $app2->ServiceID, ':incomeID' => $IncomeID)); if (!empty($detail)) { RecommendIncomeDetail::model()->updateByPK($detail->ID, array('income' => $month1)); } else { $income = new RecommendIncomeDetail(); $income->RecomID = $app2->RecomID; $income->RecomTime = time(); // $income->IncomeAccount = 0; $income->IncomeTime = time(); $income->isAccount = 0; $income->BeFormalTime = 0; $income->income = $month1; $income->OrganID = $deaval['ID']; $income->ServiceID = $app2->ServiceID; $income->incomeID = $IncomeID; $income->save(); } } } } } } $criteria = new CDbCriteria(); $criteria->select = 'BuyerID'; $criteria->distinct = true; $criteria->addCondition('Status=9'); $criteria->addCondition("ReceiptTime<" . $endmoth); $criteria->addCondition("ReceiptTime>=" . $beginmoth); $criteria->addCondition("SellerID=" . $deaval['ID']); if (!empty($serviceID)) { $criteria->addNotInCondition('BuyerID', $serviceID); } $criteria->order = 'BuyerID desc'; $payservicers = PapOrder::model()->findAll($criteria); if (!empty($payservicers)) { foreach ($payservicers as $paykey => $payval) { $record = RecommendRecord::model()->find('ServiceID=:ServiceID', array(":ServiceID" => $payval->BuyerID)); if (!empty($record)) { $month2 = 0; $paysers = PapOrder::model()->findAll('BuyerID=:BuyerID and Status=:Status and SellerID=:SellerID and ReceiptTime<:endmoth and ReceiptTime>=:beginmonth', array(':BuyerID' => $payval->BuyerID, ':Status' => 9, ':SellerID' => $deaval['ID'], ':endmoth' => $endmoth, ':beginmonth' => $beginmoth)); foreach ($paysers as $Skey => $Sval) { $discountAmount = $Sval['RealPrice'] * $discountRate; // $payAmount = is_float($discountAmount) ? substr_replace($discountAmount, '', strpos($discountAmount, '.') + 3) : $discountAmount . '.00'; $payAmount = round($discountAmount, 2); $month2 -= $payAmount; $lastmonthtotal -= $payAmount; } $detail = RecommendIncomeDetail::model()->find("OrganID=:OrganID and ServiceID=:ServiceID and incomeID=:incomeID", array(':OrganID' => $deaval['ID'], ":ServiceID" => $payval->BuyerID, ':incomeID' => $IncomeID)); if (!empty($detail)) { RecommendIncomeDetail::model()->updateByPK($detail->ID, array('income' => $month2)); } else { $income = new RecommendIncomeDetail(); $income->RecomID = $record->RecomID; $income->RecomTime = time(); $income->IncomeTime = time(); $income->isAccount = 0; $income->BeFormalTime = 0; $income->income = $month2; $income->OrganID = $deaval['ID']; $income->ServiceID = $payval->BuyerID; $income->incomeID = $IncomeID; $income->save(); } } } } RecommendIncome::model()->updateByPK($IncomeID, array('MonthIncome' => $lastmonthtotal)); } } Yii::log(date('Y-m-d H:i:s') . " [RecommendIncome] end \n", 'info', 'command'); echo date('Y-m-d H:i:s') . " [RecommendIncome] end \n"; }
public function actionServicedetail() { $id = $_GET['id']; $organID = Commonmodel::getOrganID(); //获取机构照片 $photo = ServicePhoto::model()->findAll("userId=:userId", array(":userId" => $id)); //获取修理厂基础信息(基础信息+联系方式) $model = Service::model()->find("userId=:userId", array(":userId" => $id)); //获取修理厂主营信息 $main = ServiceMain::model()->find("OrganID=:ID", array(":ID" => $id))->attributes; $routines = ServiceMainRoutine::model()->findAll("MainID=:ID AND OrganType=:Type", array(":ID" => $main['ID'], ":Type" => $main['OrganType'])); foreach ($routines as $rokey => $rovalue) { $routine[$rokey] = $rovalue->attributes; } $diagnos = ServiceMainDiagnos::model()->findAll("MainID=:ID AND OrganType=:Type", array(":ID" => $main['ID'], ":Type" => $main['OrganType'])); foreach ($diagnos as $dikey => $divalue) { $diagno[$dikey] = $divalue->attributes; } $parts = ServiceMainWearparts::model()->findAll("MainID=:ID AND OrganType=:Type", array(":ID" => $main['ID'], ":Type" => $main['OrganType'])); foreach ($parts as $pakey => $pavalue) { $part[$pakey] = $pavalue->attributes; } $repairs = ServiceMainRepair::model()->findAll("MainID=:ID AND OrganType=:Type", array(":ID" => $main['ID'], ":Type" => $main['OrganType'])); foreach ($repairs as $rekey => $revalue) { $repair[$rekey] = $revalue->attributes; } $record = RecommendRecord::model()->find("DealerID=:DealerID and ServiceID=:ServiceID", array(":DealerID" => $organID, ":ServiceID" => $id)); if (!empty($record)) { $users = Yii::app()->db->createCommand()->select("pro.truename,pro.phone")->from("tbl_user t")->join("tbl_profiles pro", "pro.user_id=t.id")->where("t.id!=:userid and t.OrganID=:userid", array(":userid" => $id))->queryAll(); } $this->render('servicerdetail', array('photo' => $photo, 'model' => $model, "main" => $main, "routine" => $routine, "diagno" => $diagno, "part" => $part, 'employs' => $users ? $users : array(), "repair" => $repair)); }