$status = false;
// 自增/自减数量 自减的话写成负数
$editData['quantity'] = new \Yii\db\Expression('`quantity` + 10');
// 普通修改字段
$editData['update_time'] = time();
// 条件
$where = ['id' => $id];
try{
$status = \Yii::$app->db->createCommand()->update(self::tableName(), $editData, $where)->execute();
}catch(\Exception $e){
$error = ['message' => '数据库错误'];
$error['info'] = $e;
\Yii::error($error);
return $status;
}
return $status;
该成自己对应的字段就行了
AR类好像可以用这个方法
table::updateAllCounters(['quantity' => 10], ['and', ['id' => 1]]);