id; $sjId = $shop->sjId; $where = [ 'shopId' => $shopId, 'time' => $time, ]; $model = self::getByCondition($where, true); if (empty($model)) { $model = self::add(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrder], true); } $id = $model->id; //查id行级锁 $stat = StatOrderCount::findBySql('select * from ' . StatOrderCount::tableName() . ' where id = :id for update', ['id' => $id])->one(); $stat->riseNum += 1; $stat->totalNum += 1; $stat->save(); return $stat->riseNum; } }