首页 > 其他分享 >yii 框架 afterSave Model 数据变更 同步数据 处理新增了逻辑

yii 框架 afterSave Model 数据变更 同步数据 处理新增了逻辑

时间:2023-07-14 17:58:48浏览次数:36  
标签:oper opn changedAttributes yii afterSave opnop Model where id


/**
* 来源
* 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();
}
}

}
}
}

标签:oper,opn,changedAttributes,yii,afterSave,opnop,Model,where,id
From: https://www.cnblogs.com/cuishilei/p/17554621.html

相关文章

  • yii 框架 Model 映射表 一对多 或 一对一
    publicfunctiongetTmsOrderTravel(){//第一个参数为要关联的子表模型类名,//第二个参数指定通过子表的user_id,关联主表的usesr_id字段//这里写清楚点大概意思就是User.user_id=>Order.user_idreturn$this->hasMany(TmsOrderTravel::className(),['tt_id'......
  • 机器翻译 | Prompting Large Language Model for Machine Translation: A Case Study
    题目:机器翻译的提示大语言模型:一个案例研究摘要对提示的研究表明,在很少甚至没有监督训练的情况下,提示在许多任务中表现出色。然而,文献中对机器翻译的提示还没有充分的研究。本文对翻译提示策略进行了系统的研究,考察了提示模板和示例选择的各种因素,填补了这一空白。我们进一步......
  • ModelWhale 推动数据开放、跨学科协同及产学研一体,以遥感领域为例
     2023年3月,科技部会同自然科学基金委启动“人工智能驱动的科学研究(AIforScience)”专项部署工作,布局“人工智能驱动的科学研究”前沿科技研发体系。对此,中国科学院院士、北京大学国际机器学习研究中心主任鄂维南认为,AIforScience是“以机器学习为代表的人工智能技术”与“科学......
  • [论文速览] Hard Patches Mining for Masked Image Modeling
    Pretitle:HardPatchesMiningforMaskedImageModelingaccepted:CVPR2023paper:https://arxiv.org/abs/2304.05919code:https://github.com/Haochen-Wang409/HPMref:CVPR2023|挖掘困难样本的MIM框架:HardPatchesMiningforMaskedImageModeling关键词:MIM......
  • C#连接Redis - Redis教程 (yiibai.com) (转)
    C#连接Redis-Redis教程(yiibai.com)classProgram{staticvoidMain(string[]args){//在Redis中存储常用的5种数据类型:String,Hash,List,SetSortedsetvarclient=newRedisClient("127.0.0.1",6379);//A......
  • elementUI远程搜索功能遇到的坑(el-autocomplete) 如果是提前加载出全量数据 去掉v-mode
    elementUI远程搜索功能遇到的坑(el-autocomplete)如果是提前加载出全量数据去掉v-model.trim换为v-model=“nameinputvalue”原文链接:https://blog.csdn.net/CuiCui_web/article/details/95939746本文主要是解决下拉框根据返回值隐藏   动态设置建议列表值等问题结构写......
  • 《ReAct: SYNERGIZING REASONING AND ACTING IN LANGUAGE MODELS》论文学习
    一、论文主要思想本文首先认为,到目前为止,LLM在语言理解方面令人印象深刻,它们已被用来生成CoT(思想链)来解决一些问题,它们也被用于执行和计划生成。尽管这两者是分开研究的,但本文旨在以交错的方式将推理和行动结合起来,以提高LLM的表现。这个想法背后的原因是,如果你考虑一下作为......
  • 风电分布式并网模型 Wind Farm Simulation Model。 Matlab/simulink
    风电分布式并网模型WindFarmSimulationModel。Matlab/simulink1、共2个火电厂,4个风电场,共15个节点。火电厂:1号火电厂,设定为SwingBus;2号火电厂,设定为PVBus。(在汽轮机调节器可进行调节励磁系统的控制方式)风电厂:4个风电厂;各个风电厂的风速可......
  • Ibatis的resultMap的cacheModel研究
    1、Ibatis的resultMap的cacheModel研究http://lggege.iteye.com/blog/216615  2、缓存cacheModelhttp://imticg.iteye.com/blog/216809......
  • vue - v-model在组件上的应用(包含子传父)
    一、v-model的参数默认情况下,v-model在组件上都是使用modelValue作为prop,并以update:modelValue作为对应的事件。我们可以通过给v-model指定一个参数来更改这些名字:<MyComponentv-model:title="bookTitle"/>在这个例子中,子组件应声明一个titleprop,并通过触发upd......