/**
* 涉及余额抵扣管理
* @param $runValidation
* @param $attributeNames
* @return bool
* @throws Exception
*/
public function save($runValidation = true, $attributeNames = null)
{
//默认已收款
$this->collection_status = self::COLLECTION_STATUS_RECEIVED;
if ($this->isNewRecord) {
$transaction = \Yii::$app->db->beginTransaction();
//账户操作
if ($this->payment_channel == self::PAYMENT_CHANNEL_ACCOUNT) {
$this->collection_channel = self::COLLECTION_CHANNEL_DEFAULT;
$this->collection_status = self::COLLECTION_STATUS_RECEIVED;
$this->collection_time = time();
}
try {
if (parent::save($runValidation, $attributeNames)) {
$a = self::findAll(['order_id' => $this->order_id]);
//余额扣款时,处理
if ($this->payment_channel == self::PAYMENT_CHANNEL_ACCOUNT) {
$company = $this->order->member->enterprise;
$company->orderDeductionBalance($this->_deductionForm);
}
$b = $this->order->orderPaymentLogs;
//触发金额变更事件
$this->order->trigger(YanbanOrder::EVENT_ORDER_AMOUNT_UPDATE);
$transaction->commit();
return true;
}
$transaction->rollBack();
return false;
} catch (Exception $exception) {
$transaction->rollBack();
throw new Exception($exception->getMessage());
}
} else {
return parent::save($runValidation, $attributeNames);
}
}
I met a problem to ask , in the database transaction, insert a piece of data, and then the direct model query can be queried out, but through the associated query can not query processing, how to solve this? Such problems can cause data inconsistencies? can you help me .