本文整理汇总了PHP中Statement::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Statement::model方法的具体用法?PHP Statement::model怎么用?PHP Statement::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement::model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateDBByData
protected static function updateDBByData(&$arrData)
{
$arrLog = [];
Yii::log("updateDBByData start", "info");
foreach ($arrData as $k => $v) {
// найти запись в {{company}}
// блокировка её FOR UPDATE
$Company = Company::model()->findByAttributes(['INN' => $v['inn']]);
if (!is_null($Company)) {
$transaction = Yii::app()->getDb()->beginTransaction();
try {
C2goActiveRecord::logStart();
$sqlCompanyBlock = 'SELECT * FROM ' . $Company->tableName() . ' WHERE `id`=:id FOR UPDATE';
$CompanyById = Company::model()->findBySql($sqlCompanyBlock, ['id' => $Company->id]);
//$sqlCheckStatementExist = 'SELECT * FROM {{statement}} WHERE `tnd`=:tnd AND `sum`=:sum AND `inn`=:inn AND `date`=:date';
$arrParams = ['tnd' => $v['tnd'], 'sum' => $v['sum'], 'date' => static::convertXMLDate($v['date']), 'inn' => $v['inn']];
$StatementCheck = Statement::model()->findByAttributes($arrParams);
if (is_null($StatementCheck)) {
// добавить
$Statement = new Statement();
$Statement->tnd = $v['tnd'];
$Statement->sum = $v['sum'];
$Statement->date = static::convertXMLDate($v['date']);
$Statement->inn = $v['inn'];
$Statement->name = $v['name'];
if (!$Statement->save()) {
throw new CException(Yii::t('StatementModule.default', 'Не могу сохранить запись в Statement,errors', ['errors' => print_r($Statement->getErrors(), true)]));
}
Yii::log("updateDBByData p3 ", "info");
//@todo: log.processed
static::addToStatementLog($Statement, StatementLog::PROCESSED, $CompanyById);
Yii::log("updateDBByData p4 ", "info");
// verify
if (!$CompanyById->verify || !$CompanyById->validate) {
$CompanyById->verify = 1;
$CompanyById->validate = 1;
if ($CompanyById->save()) {
//@todo: log.verified
static::addToStatementLog($Statement, StatementLog::VERIFIED, $CompanyById);
} else {
throw new CException(Yii::t('StatementModule.default', 'Не могу в Company сделать verify=1,validate=1 ,errors', ['errors' => print_r($CompanyById->getErrors(), true)]));
}
}
// company.balance
$CompanyById->balance += $v['sum'];
if ($CompanyById->save()) {
$AccountMotion = new AccountMotion();
$AccountMotion->company_id = $CompanyById->id;
$AccountMotion->price = $v['sum'];
$AccountMotion->notice = "import statement Statement.id=[{$Statement->id}]";
if ($AccountMotion->save()) {
//@todo: log.enrolled
static::addToStatementLog($Statement, StatementLog::ENROLLED, $CompanyById);
//sleep(5);
$transaction->commit();
$arrLog[] = ['success'];
C2goActiveRecord::logEndAndWrite();
} else {
throw new CException(Yii::t('StatementModule.default', 'Не могу добавить в AccountMotion ,errors', ['errors' => print_r($AccountMotion->getErrors(), true)]));
}
} else {
throw new CException(Yii::t('StatementModule.default', 'Не могу в Company изменить balance ,errors', ['errors' => print_r($CompanyById->getErrors(), true)]));
}
} else {
throw new CException(Yii::t('StatementModule.default', 'Statement запись уже есть'));
}
} catch (Exception $e) {
$transaction->rollback();
$strException = $e->__toString();
Yii::log("updateDBByData exception [{$strException}]", "error");
$arrLog[] = ['error', $e->getMessage()];
C2goActiveRecord::logEmptyMessages();
} finally {
C2goActiveRecord::logEnd();
}
} else {
$arrLog[] = ['error', Yii::t('StatementModule.default', 'Не найдена компания по INN, inn_value', ['inn_value' => $v['inn']])];
}
//@todo: delete
//break;
}
Yii::log("updateDBByData end", "info");
return $arrLog;
}
示例2: actionStatementView
public function actionStatementView()
{
$id = Yii::app()->request->getParam('id', null);
$Statement = Statement::model()->findByPk($id);
$this->render('view_statement', ['Statement' => $Statement]);
}