getPk(); $model = new \app\admin\model\xilufitness\user\Index; $user_info = $model->where(['id' => $row['user_id'] ?? 0, 'brand_id' => $row['brand_id'] ?? 0])->find(); if(!empty($user_info) && !empty($row['amount'])){ $update_data['before_account'] = $user_info['account']; if($row['amount_type'] == 1){ $update_data['after_account'] = bcadd($user_info['account'],$row['amount'],0); } else { $update_data['after_account'] = bcsub($user_info['account'],$row['amount'],0); } $update_data['updatetime'] = time(); $result = $row->getQuery()->where($pk,$row[$pk])->update($update_data); if(false !== $result){ $user_info->allowField(true)->save(['account' => $update_data['after_account'] ?? 0]); } } }); } /** * 关联用户 */ public function user(){ return $this->belongsTo('\\app\\admin\\model\\xilufitness\\user\\Index','user_id','id',[],'LEFT')->setEagerlyType(0); } /** * 关联品牌 */ public function brand(){ return $this->belongsTo('\\app\\admin\\model\\xilufitness\\brand\\Index','brand_id','id',[],'LEFT')->setEagerlyType(0); } }