/**
* 来源
* 1.Model::updateAll()
* 2.Model::findOne(id)->save()
* @param $attributes
* @param $condition
* @param $params
* @return int
* @throws \yii\db\Exception
*/
public static function updateAll($attributes, $condition = '', $params = [])
{
//这里需要提前抛出,如果执行后抛出,同样的条件可能查不到对应的数据,导致更新失败
(new self())->afterSave(false, array_merge(['where' => $condition], $attributes));
$command = static::getDb()->createCommand();
$command->update(static::tableName(), $attributes, $condition, $params);
return $command->execute();
}
public function afterSave($insert, $changedAttributes) {
parent::afterSave($insert, $changedAttributes);
if ($insert) {
$primaryKey = $this->getPrimaryKey();
$data = $this->isOneUserOrder($primaryKey);
if($data){
$this->addData($data);
}
}
if(isset($changedAttributes['where']) && isset($changedAttributes['opnop_visible'])){
if($changedAttributes['opnop_visible'] == 1){
if(isset($changedAttributes['where']['opnop_id'])){
$opnop_id = $changedAttributes['where']['opnop_id'];
$opn_operator = OpnOperator::find()->select('opn_id,user_id,username')->where(['opnop_id'=>$opnop_id])->asArray()->one();
$opn_id = $opn_operator['opn_id'];
$oper = TmsOperationFee::find()->where(['opn_id'=>$opn_id])->one();
if($opn_operator && $oper){
$oper->user_id = $opn_operator['user_id']?:0;
$oper->username = $opn_operator['username']?:'';
$oper->save();
}
}
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构